Re: Improvements to http://perl-begin.org/

2009-08-14 Thread Offer Kaye
On Thu, Aug 13, 2009 at 11:06 PM, Steve Fink wrote:

 I'm referring to http://perl-begin.org/style.css line 40 (according to
 Firebug), specifically this CSS:

  #page-container { ... width:780px; }

 Bad!


I have to say, the site looks very good visually - I haven't looked at
the contents yet, but in terms of initial visual impact - it's very
good. You've chosen a good template :)
However I have to agree with Steve, having the fixed 780px width is
annoying. My problem is the reverse of Steve, I have a large screen
and having all the content crammed in a relatively small area in the
middle of the screen doesn't add anything.

Regards,
-- 
Offer Kaye

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: argument for Math::MatrixReal

2006-08-22 Thread Offer Kaye

On 8/21/06, chen li wrote:

Dear all,

I read a file into an array reference. I want to pass
it as an argument when create the new object from
Math::MatrixReal. But when I read the usage of this
module I can't find how. Does anyone there give me a
hand?

Thanks,

Li

Here are the code I use:

my $ref_AoA=[
[1,2,3,],
[1,2,3,],
[1,2,3,],
  ];

my $array_object=Math::MatrixReal-new ($ref_AoA);
##the line doesn't work for me.



Instead of new you should be using the new_from_cols constructor:
my $array_object=Math::MatrixReal-new_from_cols($ref_AoA);

You can test the resulting object using:
print $array_object;

HTH,
--
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Error handling on script

2006-07-24 Thread Offer Kaye

On 7/24/06, joseph tacuyan wrote:

How can rewrite it, so even it encounters such an error it would still
continue? Thank you for all the help.


Change this:
my $name = gethostbyaddr(inet_aton($address), AF_INET)
  or die Can't resolve $address: $!\n;
print OUTPUT $_ =$name \n;

to:
my $name = gethostbyaddr(inet_aton($address), AF_INET);
if ($name) {
  print OUTPUT $_ =$name \n;
} else {
  warn Can't resolve $address: $!\n;
}

HTH,
--
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: FORMAT question

2006-07-05 Thread Offer Kaye

On 7/5/06, Jeff Peng wrote:


Hello,
I think there are not relation between your implement and the filehandle.


As far as I can tell, a format must have the same name as the
filehandle to which you want to print it, and once you define a format
you cannot change it. So these 2 facts mean you can't have more than 1
format per filehandle. Am I wrong?


To avoid the fact that I have been wrong for understanding your
meaning,maybe you would paste some of your codes here.


Here is the code that prints out a bunch of warnings to STDERR and in
the output file prints only the second table:
#! /usr/bin/env perl
use strict;
use warnings;

my $outfile = file_with_tables.txt;
open(OUT,$outfile) or die Couldn't open $outfile for writing: $!\n;
print OUT Table 1:\n;
_print_format1(1,15,foo);
_print_format1(2,8,bar);
print OUT \nTable 2:\n;
_print_format2(clk1, 0.04, 12000, 0.51, 0.39, 0.25);
_print_format2(clk2, 0.13, 27000, 0.8, 0.5, 0.1);
close(OUT) or die Couldn't close $outfile after writing: $!\n;

sub _print_format1 {
# output table 1, with 3 columns
my($id,$num_occur,$msg) = @_;
format OUT =
@ @  @
$id,$num_occur,   $msg
.
write OUT;
}   

sub _print_format2 {
# output table 2, with 6 columns
my($clock,$skew,$num_ffs,$max_lat,$min_lat,$max_tran) = @_;

format OUT =
@ @  @ @ @
@
$clock,   $skew,  $num_ffs,  $max_lat,  $min_lat,  $max_tran
.
write OUT;
}   

# The End!


Here a script that illustrates my current workaround:
#! /usr/bin/env perl
use strict;
use warnings;

my $outfile = file_with_tables.txt;
open(OUT,$outfile) or die Couldn't open $outfile for writing: $!\n;
print OUT Table 1:\n;
_print_format1(1,15,foo);
_print_format1(2,8,bar);
close(OUT) or die Couldn't close $outfile after writing: $!\n;
open(NEWOUT,$outfile) or die Couldn't open $outfile for writing: $!\n;
print NEWOUT \nTable 2:\n;
_print_format2(clk1, 0.04, 12000, 0.51, 0.39, 0.25);
_print_format2(clk2, 0.13, 27000, 0.8, 0.5, 0.1);
close(NEWOUT) or die Couldn't close $outfile after writing: $!\n;

sub _print_format1 {
# output table 1, with 3 columns
my($id,$num_occur,$msg) = @_;
format OUT =
@ @  @
$id,$num_occur,   $msg
.
write OUT;
}   

sub _print_format2 {
# output table 2, with 6 columns
my($clock,$skew,$num_ffs,$max_lat,$min_lat,$max_tran) = @_;

format NEWOUT =
@ @  @ @ @
@
$clock,   $skew,  $num_ffs,  $max_lat,  $min_lat,  $max_tran
.
write NEWOUT;
}   

# The End!

Hope this helps,
--
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: FORMAT question

2006-07-05 Thread Offer Kaye

On 7/5/06, John W. Krahn wrote:


#!/usr/bin/perl
use warnings;
use strict;

sub _print_format1 {
# output table 1, with 3 columns
$^A = '';
formline 'FORMAT', @_;
@ @  @
FORMAT
$^A;
}



Wow. That's... impressive. Very perl-foo-ish :)
A simple and nice solution, kind-of bypassing the entire FORMAT and
write mechanism and going right to the internals. I like it :)

After looking at the docs again I also found this solution. The
problem is, I don't understand what it does :)

use FileHandle;
#...
sub _print_format2 {
# output table 2, with 6 columns
my($clock,$skew,$num_ffs,$max_lat,$min_lat,$max_tran) = @_;

format_name OUT NEWOUT;

format NEWOUT =
@ @  @ @ @
@
$clock,   $skew,  $num_ffs,  $max_lat,  $min_lat,  $max_tran
.
write OUT;
}   

What exactly does 'format_name OUT NEWOUT;' *do*?

Well, I now have like 4 different working solutions to this problem.
Just have to choose... :)
Thanks,
--
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




FORMAT question

2006-07-04 Thread Offer Kaye

Hi,
Can anyone tell me if it is possible to define 2 different formats for
the same filehandle?

The reason I am asking is that I want to print 2 different tables to
the same text file and I don't want to use printf statements. For me
at least, code that uses printf to print something as complex as a
text table is hard to both write and read, hard to understand and hard
to debug. It's also ugly, to boot :)

My current workaround is to close the file, reopen in append mode with a
different filehandle name and define the second format with this name.
Ugly, but works. Any other/better solutions?

Thanks in advance,
--
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




hex conversion to dec - print and printf differences

2006-04-11 Thread Offer Kaye
Hi,
This is probably trivial, but I couldn't find a mention of this
anywhere - why do the following 2 code lines produce different
results?
 perl -e 'printf %d\n ,0x_'
-1
 perl -e 'print 0x_ , \n'
4294967295

Even stranger:
 perl -e 'printf %d\n ,0x8000_'
-2147483648
  perl -e 'print 0x8000_ , \n'
2147483648
 perl -e 'print 0x8000_ - 0x1 , \n'
2147483647
 perl -e 'printf %d\n ,0x8000_ - 0x1'
2147483647

This is on a 32bit Linux OS.

Thanks,
--
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hex conversion to dec - print and printf differences

2006-04-11 Thread Offer Kaye
On 4/11/06, John W. Krahn wrote:
  This is probably trivial, but I couldn't find a mention of this
  anywhere - why do the following 2 code lines produce different
  results?
 perl -e 'printf %d\n ,0x_'
  -1
 perl -e 'print 0x_ , \n'
  4294967295

 perldoc perlnumber


Hi John,
Thanks for the pointer, I guess you wanted me to see the All the
operators which need an argument in the integer format treat the
argument as in modular arithmetic sentence.

But why is print behaving differently? I.e., why is the 0x_
not treated as a number?

Thanks,
--
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: parsing columns

2005-08-18 Thread Offer Kaye
On 8/18/05, Wiggins d'Anconia wrote:
 
 Though in that case I guess you might be able to determine that it is
 column two because there aren't two spaces, 

Alas, were it that simple... :( An extra space will not be included,
even if the l3dat2 would actually have been l3dat3...

 but that is still using the
 assumption that there *must* be at least one space character delimiting
 columns.

1. There *must* be at least one space character between columns.
2. Data is guaranteed not to include a whitespace.

Regards,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: parsing columns

2005-08-14 Thread Offer Kaye
On 8/14/05, Manav Mathur wrote:
 
 How do you logically determine that l2dat4 in line 2 is column 4 and not
 column 2??
 
 Manav
 

Because as a human, I can see they are aligned.
I guess a program will have to count whitespace, but then there is the
issue of line 3...

Regards,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




parsing columns

2005-08-13 Thread Offer Kaye
Hi all,
I have a text file with columns, where the columns may not be aligned,
and not all lines may have data in all columns:

header1 header2 header3header4

l1dat1l1dat2l1dat3  l1dat4
l2dat1l2dat4
l3veryveryveryverylongdat1 l3dat2

As you can see, line1 has all data, line2 is missing clomuns 2 and 3,
line 3 is a mess :)

Any thoughts on parsing such a table?
Please don't offer solutions suggesting to change the way the text
file is written, I have no control over that...

Regards,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: popping, shifting or splicing an array???

2005-08-09 Thread Offer Kaye
On 8/9/05, DBSMITH wrote:
 
 Hello ...
 
 I am trying to figure out, which operator to use; pop, shift or splice.
 My goal is,  as an option is selected from user input,  pop or splice or
 shift elements off ( those selected from user input ) and repopulate array
 with remaining elements.
 

Hi,
First of all, I don't grok your splice examples. According to
'perldoc -f splice' (http://perldoc.perl.org/functions/splice.html),
the second argument to splice should be an offset - i.e. a number. So
@numbers to remove will be interpreted in scalar context, and the
offeset into @ArrayA will be the lengh of the list of numbers to
remove. Is that what you wanted?

A second point is that you use shift inside a for loop. That's *BAD*:
If any part of LIST is an array, foreach  will get very confused if
you add or remove elements within the loop body, for example with
splice. So don't do that. (perldoc perlsyn)

pop removes that last value of an array (shortning the array).
shift also shortens the array, but by removing the first element.
Which one you want to use depends on what your array looks like and
what you want to do. In any case you don't need to repopulate the
array - both pop and shift change the array itself. Finally, note that
splice can 'emulate' both operators - see the splice perldoc page
for examples.

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Is there any Makefile.pl example?

2005-08-09 Thread Offer Kaye
On 8/9/05, Yu Wang wrote:
 Hi,
 
 I have written a program using Gtk2 in Perl. It's the first time I write 
 program
 in Perl, so I need some help in writting the Makefile.pl
 
 I have 1 file for main program, and 5 files for modules. Besides that, I also
 have document files and some data files to be accessed by the code.
 
 I have read a tutorial about Makefile.pl, but it only teaches me how to 
 install
 modules in to perl module directories. It seems that I couldn't find a 
 tutorial
 on how to write Makefile.pl to perl applications.
 
 So is there anyone can provide an example or suggest some directions?
 
 Any help is greatly appreciated!
 
 Yu Wang
 

Makefile.PL uses ExtUtils::MakeMaker, which is geared towards, as you
said yourself, Perl module installation.
What you are looking for is a way to write a Makefile (*not* a
Makefile.PL) which will install your Perl application. This is
outside the realm of Perl - where/how you install your app depends on
your system and on your own decisions. Actually you are better off
using your system's native packaging utilities for the app
installation - deb, rpm or whatever you use.

If you would like to write a Makefile.PL for each of the modules
distributed with your app so that the modules are installed inside the
standard Perl modules installation directories, I suggest reading:
http://search.cpan.org/dist/ExtUtils-MakeMaker/lib/ExtUtils/MakeMaker/Tutorial.pod

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




HaMakor Prize

2005-07-14 Thread Offer Kaye
http://www.hamakor.org.il/prize.html

There are five finalists nominated for the prize, one of them is our
very own Gabor Szabo.

Congratulations Gabor and good luck!

If you are already a member/friend of HaMakor, you should have
received an email from them urging you to vote. So go do it :)
If you aren't a member/friend, you need to register in order to vote.
What are you waiting for? ;-)

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Perl training material required.

2005-07-01 Thread Offer Kaye
On 7/1/05, Nilay   Puri, Noida [EMAIL PROTECTED] wrote:
 
 Hi All,
 
 Can anyone provide me the site which have good teaching material for perl.
 
 I need to give training on perl basics and I don't have time to prepare the 
 material.
 
 Thanks in advance.
 

http://perldoc.perl.org/perlintro.html
http://perltraining.com.au/notes.html

Search Google, many universities have course notes for beginner level
Perl courses.

Regards,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Esol and pod2html translation problem

2005-06-08 Thread Offer Kaye
On 6/7/05, Offer Kaye wrote:
 Hi all,
 I have a POD file with the following link:
 L/$/
 podchecker complained about this (node '$/' contains non-escaped | or
 /), so I looked at perlpod and read that I should use Esol
 instead of a literal / inside an L... link.
 But now, after running Pod::Html, I get HTML that has the string
 sol; in it, which in the browsers I checked (checked both IE and
 Firefox) showed as the string sol; and not as the character /.
 
 Should I go back to using L/$/ and ignore the podchecker warnings?
 Is this a known Pod::Html bug?
 Or perhaps a bug in the browsers I used?
 
 What can I do to solve this issue (without having to dig into the
 Pod::Html internals :))?
 
 TIA,
 --
 Offer Kaye
 

As no one answered, let me re-phrase the question - which tool do
*you* use to translate POD to HTML? Do you also use pod2html or do
you use something else?

Thanks again,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: [OT] Is there a policy regarding subscrjbers with challenge/respo nse mail filters?

2005-06-08 Thread Offer Kaye
On 6/6/05, Chris Devers wrote:
 
 Or -- shock horror -- get a gmail / hotmail / yahoo / etc account 

Why *horror*? Gmail rocks :)
Email me if you want an invitation.

Cheers,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: if else w/ wanted

2005-06-07 Thread Offer Kaye
On 6/6/05, Brian Volk wrote:
 Hello All,
 
 I'm working w/ the File::Find module for the first time and I'm having
 problems w/ my else statement..  If the query does not match the first file
 in the directory, it will print the else statement.  I would like it the if
 statement to continue on to the next file in the directory to see if that
 matches and if so, print the if statement
 

Hi Brian,
I'm not sure what your problem is, I think you need to re-read
perldoc File::Find. What you are describing (would like... to
continue on to the next file) is exactly what File::Find does. Think
of it this way: for each search path you give find() as an argument,
wanted will be executed once per every file in and under the given
path.

Here's some simple code as an example:
## begin code
use strict;
use warnings;
use File::Find;
find(\wanted, '.');
sub wanted {
   return if(m/^\./);
   print $_\n;
}
## end code
This code will print the filename of every file (remember that
directories are considered files in Unix!) under the current
directory, except for hidden files.

 
 undef $/;

Why?

 
  return if($_ =~ /^\./);
...
  if ( m/$query/i ) {

Why use 2 forms for matching $_? Try to be consistent, it really helps
readability...

  stat $File::Find::name;
 

Again, why? Especially as you are calling stat in empty context,
throwing away the return value. So why call it in the first place?

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Esol and pod2html translation problem

2005-06-07 Thread Offer Kaye
Hi all,
I have a POD file with the following link:
L/$/
podchecker complained about this (node '$/' contains non-escaped | or
/), so I looked at perlpod and read that I should use Esol
instead of a literal / inside an L... link.
But now, after running Pod::Html, I get HTML that has the string
sol; in it, which in the browsers I checked (checked both IE and
Firefox) showed as the string sol; and not as the character /.

Should I go back to using L/$/ and ignore the podchecker warnings?
Is this a known Pod::Html bug?
Or perhaps a bug in the browsers I used?

What can I do to solve this issue (without having to dig into the
Pod::Html internals :))?

TIA,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: find and replace large blocks

2005-06-07 Thread Offer Kaye
On 6/7/05, Cy Kurtz wrote:
 Is it possible to use s/foo/bar in another way to allow replacement of
 large blocks of text with spaces, quotes, and double quotes?
 

Yes.

 Is there a better way?
 

That depends on what exactly you want to do.
HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: find and replace large blocks

2005-06-07 Thread Offer Kaye
On 6/7/05, Chris Devers wrote:
 
 Which matches a dot /./ -- which is a metacharacter meaning matches
 anything at all 

Not quite correct - a dot (.) matches any single character, not
anything at all, and even this rule has an exception - a dot will
not match a newline (\n) unless you use the s modifier.

 
 In other words, it will turn this string --
 
 abc
 
 -- into this
 
 officers-gasenate.htmlofficers-gasenate.htmlofficers-gasenate.html
 

No, it will turn abc into:
   officers-gasenate.htmlbc
Unless you use the g modifier.

 
 Thus, the regex should be something like this:
 
 s|\./officers-gasenate\.html|http://www\.legis\.state\.ga\.us/cgi-bin/peo_list\.pl\?List=stsenatedl|
 

There's no need to escape metachars in the replacement part. Without
modifiers (such as e or x) the replacement part is treated as a
simple double-quoted string (delimiter dependent).
So the s/// can be written as:
s|\./officers-gasenate\.html|http://www.legis.state.ga.us/cgi-bin/peo_list.pl?List=stsenatedl|

Cheers,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: [OT] Is there a policy regarding subscrjbers with challenge/respo nse mail filters?

2005-06-06 Thread Offer Kaye
On 6/6/05, Daniel Kasak wrote:
 Thomas Bätzler wrote:
 
 Does this get on other people's nerves, too:
 

Yes, it does.

 
 There's no policy AFAIK, but I agree that it would be great to have one.
 Possibly we could also unsubscribe people who put a vacation message on
 their account?

I second that. Especially with regards to anti-spam messages. Those
are pure spam on a moderated mailing list.

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Search Pattern Question: What does # mean?

2005-06-06 Thread Offer Kaye
On 6/6/05, Siegfried Heintze wrote:
 I'm using regular expressions to parse job titles and I had C# in a pattern
 and it was not working correctly. I corrected the problem with C\#. What
 does C# match?
 

# has no special meaning in REs (it's not a metacharacter), so you
would have to show us some code that fails with the above pattern.
Off-hand I can't think of any reason why C\# would match while C#
would not.

Regards,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: HOw to pass patterns as function argments?

2005-06-06 Thread Offer Kaye
On 6/5/05, Siegfried Heintze wrote:
 I have a fragment of code (consisting of a while loop) that removes all the
 keywords in string and puts them at the end. I would like to extract this
 while loop into it's own function and have patterns as function arguments.
 
 What should I pass to the function? Strings?
 

You can pass strings without a problem.
For effeciency, you can use the qr// operator. See perldoc perlop:
http://perldoc.perl.org/perlop.html#qr%2fSTRING%2fimosx

Please note however that the second part in the s/// operator is *not*
treated as an RE, only the first part:
s/PATTERN/REPLACEMENT/
PATTERN is a regexp.
REPLACEMENT is treated as double-quoted text (delimiter dependent)
unless you use the e modifier, in which case REPLACEMENT will be
eval'ed as a Perl expression.

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: why die; produce an error?

2005-06-06 Thread Offer Kaye
On 6/5/05, Ing. Branislav Gerzo wrote:
 Hi all,
 
 I noticed strange behavior with die;
 Here is snippet:
 
 use strict;
 use warnings;
 use WWW::Mechanize;
 
 my $mech = WWW::Mechanize-new();
 $mech-agent_alias('Windows IE 6');
 $mech-get( 'http://www.zoznam.sk' );
 for my $link ( $mech-links() ) {
 print $link-url_abs, \n;
 }
 
 
 This works quite OK, but when I put die; at the end of script it
 throws me an error:
 Can't locate URI/javascript.pm in @INC (@INC contains: c:/Perl/lib 
 c:/Perl/site/
 lib .) at (eval 19) line 3.
 ...propagated at myscript.pl line 10.
 
 at line 10 is die;
 
 Whats going here ?
 

I can't reproduce your problem, using perl 5.8.6 on Linux,
WWW::Mechanize version 1.12 . The script I'm using (test.pl):
### begin code
use strict;
use warnings;
use WWW::Mechanize;
my $mech = WWW::Mechanize-new();
$mech-agent_alias('Windows IE 6');
$mech-get( 'http://www.google.com/' );
for my $link ( $mech-links() ) {
   print $link-url_abs, \n;
}
die;
### end code

I'm running it using perl test.pl. The output from this is:
### begin output
http://www.google.co.il/imghp?hl=iwtab=wi
http://www.google.co.il/grphp?hl=iwtab=wg
http://www.google.co.il/dirhp?hl=iwtab=wd
http://www.google.co.il/advanced_search?hl=iw
http://www.google.co.il/preferences?hl=iw
http://www.google.co.il/language_tools?hl=iw
http://www.google.co.il/intl/iw/about.html
http://www.google.com/ncr
Died at aaa.pl line 10.
### end output
(the die statement is on line 10).

So the problem is:
1. In some other code you didn't show
2. Specific to your OS, Perl version of W::M version

I suspect reason 1 is the culprit :)

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: why die; produce an error?

2005-06-06 Thread Offer Kaye
On 6/6/05, Thomas Bätzler wrote:
 
 Off the top of my head I'd say that when parsing the links on
 the page you requested, WWW::Mechanize creates an URI object for
 each link that is found. The URI class is subclassed by the URI
 request scheme (i.e. URI::http, URI::nttp, ... ) and the needed
 subclass is loaded dynamically by URI.pm:
 

Cool, I didn't know that :)
Thanks for the great explanation Thomas, I was wondering why W::M was
looking for something called URI::javascript, you answered that
perfectly.

As a side issue, I tried running the failing script using Devel::ebug
and could not quite reproduce this issue. I'm using the latest
Devel::ebug version (0.43). Has anyone had any success using this
module for debugging work?

Cheers,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: regarding problem with $1 in regexec

2005-06-06 Thread Offer Kaye
On 6/6/05, Nischi wrote:
 Hello
 i am having something like this ...
 
 $b = \xa0\xa0\xa0\x{100} =~ /(\xa0+)/;

Try not to use $b (or $a) as variable names. $a and $b are the
special Perl sort variables and using them can cause strange bugs, for
example because even under use strict you can use $b without
declaring it.

 $b =~ \(\xa0+)\;

What is this line supposed to do? This does not compile...

 print Valid if ($1 eq \xa0\xa0\xa0;

You are missing a ) before the ; at the end. Again, this is a
compile-time error.

 print  $b $1;
 
 Here according to the regular expression the $1 should contain the matching 
 string. so 
 according $1 should have \xa0\xa0\xa0. This is happening in ASCII platform 
 but it is not 
 working in the EBCIDIC.
 
 as x{100} is 2 byte character, \xa0 will also get converted to double byte 
 which is valid. 
 The strange thing is in $1 \xa0 is 4 bytes.
 
 Why is that $1 is containing 4 bytes, why data is not correct.
 
 PS: all these is happening only in EBCIDIC platform. in ASCII it is fine.
 

As I don't have access to an EBCIDIC platform, I can't check this.
However this should work:
use strict;
use warnings;
my $bb = \xa0\xa0\xa0\x{100} =~ /(\xa0+)/;
print Valid\n if ($1 eq \xa0\xa0\xa0);
print $bb $1\n;

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: regarding problem with $1 in regexec

2005-06-06 Thread Offer Kaye
On 6/6/05, Nischi wrote:
 This works in ASCII but my question is why is it not working in EBCIDIC. why
 $1 is not having \xa0\xa0\xa0. 

As I said, I don't know. I don't have access to such a system. (It's
called EBCDIC, by the way - no I between the C and D)

Maybe it's your Perl version.  What is the output of perl -V?

Try reading perldoc perlebcdic
http://perldoc.perl.org/perlebcdic.html

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: question about appending spaces to each line of a file

2005-06-06 Thread Offer Kaye
On 6/6/05, Nupur Pande wrote:
 The interesting thing is chomping twice did not
 seem to help either. 

Of course not. chomp removes $/ only, and unless you changed it,
it is equal (on Linux) to \n. Read perldoc -f chomp
(http://perldoc.perl.org/functions/chomp.html). As an experiment, try
doing:

while (defined(my $line = Filehandle1)) {
 local $/ = \r\n;
 chomp $line;
 # rest of code...
}

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Finding matching HTML tags

2005-06-02 Thread Offer Kaye
On 6/2/05, Nilay   Puri, Noida wrote:
 Hi All,
 
 while reading a html file from perl script, I want to ensure that all HTML
 tags have closing HTML tags.
 If closing HTML tags are not there, then, I need to put the closing tag in
 place.
 
 Can anyone guide in this regard ?
 
 Thanks  Regards.
 

There is no way, even in theory, to *always* correctly close an open
HTML tag. Here's a trivial example:
   psome text strongsome more text/p
Can any program correctly close the strong tag? Should it close the
some word or all of the remaining text until the /p?

You can use HTML::Parser (http://search.cpan.org/dist/HTML-Parser/) to
parse the HTML and use if statements to check for a missing closing
tag. I think this will be very hard :)
I think you are better of using an existing tool to clean up your
HTML. Although not a Perl tool, I recommend HTML Tidy:
http://tidy.sourceforge.net/

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to upgrade local module using -MCPAN?

2005-05-26 Thread Offer Kaye
On 5/26/05, Yu Wang wrote:
 Hi, All
 
 I am curious about how to upgrade local module in 'perl -MCPAN -e shell'?
 
 Thanks!
 
 Yu
 

Do an install, this will replace and effectively upgrade the module.
There are exceptions, specific modules where this upgrade might
cause you to have 2 versions of certain files, but for most cases a
simple:
cpan install Module::Name
should work.

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: absolute path of current process

2005-05-26 Thread Offer Kaye
On 5/26/05, Peter Rabbitson [EMAIL PROTECTED] wrote:
 Is this:
 
 my $path = [File::Spec-splitpath (File::Spec-rel2abs ($0))]-[1];
 
 the only OS independent (unix/win32) way to determine the absolute path of
 the directory which contains the current process, or there is a less cryptic
 way that I am overlooking?
 

What do you mean by current process?
If you mean the path to the currently running executable ($0), You
can use a combination of the abs_path function from Cwd together with
dirname from File::Basename :
use Cwd qw(abs_path);
use File::Basename qw(dirname);
my $path = dirname(abs_path($0));

However please note that the current process may be running in an
entirely different directory then the one that hold the executable. To
find the current directory, use:
use Cwd qw(cwd);
my $path = cwd();

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hash reference help

2005-05-25 Thread Offer Kaye
On 5/24/05, Ing. Branislav Gerzo wrote:
 
 it was easy mistake, everything we should know about this is avoid
 using keys() on %$hr in while loop, because it resets iterator. That's
 all. 

Well, that, and don't change the hash inside the while loop. In your
original email you wrote:
and get_something() change the hash
That's a no-no according to perldoc -f each: If you add or delete
elements of a hash while you're iterating over it, you may get entries
skipped or duplicated, so don't.

Cheers,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: while loop - map

2005-05-25 Thread Offer Kaye
On 5/24/05, Robert Citek wrote:
 
 I found a variation of this in the Perl Nutshell book:
 
 $ perl -le '
   $foo=fee fie foe foo ;
   while ($foo =~ m/e/g ) {
 push @bar, pos $foo ;
   }
   print join(:, @bar); '
 2:3:7:11
 
 Is there an equivalent way to do the same using map instead of an
 explicit while loop?  I'm guessing not, since map is expecting a list
 and not a scalar, which $foo is.
 

This is Perl, these is always another way :)

my $foo = fee fie foe foo; 
my $sum;
my @bar = map {$sum+=1+length} split(/e/,$foo);
print join(:, @bar[0..$#bar-1]) . \n;

It is however a bit forced. I would stick to the while - much more readable :)
Cheers,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Process Running Time

2005-05-25 Thread Offer Kaye
On 5/24/05, Guohong Hu wrote:
  
 Hi, I am reading a text file (XML) and for each chunk of the file content, I
 run a subroutine (sub1) to analyze it. A problem I met is after a certain
 point of the input file (for example, after chunk #100), the sub1 suddenly
 gets significantly slower. 
   
 It seems not a memory problem, because in sub1 I only do 1) read but not
 modify some global hashes and arrays 2) read the file chunk content, and use
 some private variables to analyze it, then print out the results. So sub1 is
 not loading anything into the memory after exit. 
   

You're asking a very general question. Without access to some code and
data that causes the problem, there is no way anyone can give you
specific suggestions. The problem could be in your code, the modules
you use, or simply the interaction of the code and specific data you
are reading (e.g. some feature of the data after chunk #100 that
causes the slowdown).

For one thing, you say the sub1 suddenly gets significantly slower.
How do you know this?
Have you run Devel::DProf or some other benchmarking or profiling code?

Try to use Devel::ebug or the Perl debugger to help you pin-point the
problem. Write a test-case with minimal code and data that shows the
problem, and post that to this list. Then maybe someone can help :)

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Process Running Time

2005-05-25 Thread Offer Kaye
Oops- replied to wrong list :) Please ignore...

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: output in a single line

2005-05-25 Thread Offer Kaye
On 5/25/05, Manav Mathur wrote:
 
 our $rupee = STDIN;
 chomp($rupee) ;

Vineet,
This is a quote from perldoc perlop:
In scalar context, evaluating a filehandle in angle brackets yields
the next line from that file (the newline, if any, included),
Manav's solution involves removing the newline using chomp. You can
also write this in one line if you want (read perldoc -f chomp for
details):
chomp(our $rupee = STDIN);

Finally and unrelated, unless you have a very good reason to make
$rupee and $rupee_c1 global, I would change the declaration to my
instead of our. Don't use globals without a good reason, it's a bad
habit :-)

Cheers,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: undefined...

2005-05-23 Thread Offer Kaye
On 5/23/05, Ley, Chung wrote:
 
 Use of uninitialized value in array element at 
 /usr/lib/perl5/site_perl/5.8.0/GD/Graph/boxplot.pm line 470.

Do a dump of the data passed to GD that causes this warning, make sure
you are not passing any uninitialized data.

 I am dumbfounded...  I am thinking that somehow maybe the perl 
 compiler/interpreter is 
 doing some optimzation that is different when the size of your perl program 
 is at a different 
 size
 

No. Never. At least, not AFAIK. Maybe one of the list gurus can say otherwise.

Cheers,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: undefined...

2005-05-22 Thread Offer Kaye
On 5/22/05, Ley, Chung wrote:
 
 Upon further inspection of the array that I passed into the call, I find out 
 that for some reasons, 
 my array's last couple of elements are defined but without any values.  My 
 first thought was 
 that somehow I might have did something like this in my code:
data[0][1] = $yield; (where $yield was an undefined value).
 So, I did a check on $yield value first before assigning it...  That didn't 
 seem to solve the 
 problem...  My next assumption is that maybe I somehow skipped over some of 
 the elements 
 like so:
data[0][1] = $yield;
data[0][100] = $yield;
 where the middle 99 elements were unassigned and that perl automatically 
 defined them.  I 
 used print statements and didn't seem to notice this problem...
 

(nipicking - you wrote data[0][1] without the $ sign before data.
Try to be exact when posting your code, it might make you think of
something you forgot in your code.)

How did you use print statements? Did you use Data::Dumper? Try:
   use Data::Dumper;
   print Dumper ([EMAIL PROTECTED]);
Just before you pass @data to GD::Graph::Boxplot. You should see which
values are undefined, although perhaps that will not help you to
understand why they are not defined.
You might also want to try out the Devel::ebug module, it's very nice :)
http://search.cpan.org/dist/Devel-ebug/

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: assigning printf statement to an array

2005-05-21 Thread Offer Kaye
On 5/21/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Here is my code, but I am not seeing the elements being populated as I say
 show me the data in element 1
 Line 28 is not working after executing line 30.
 Any ideas?
 

You probably want to use sprintf instead of printf. Read perldoc
-f printf and perldoc -f sprintf from your command-line, or online:
http://perldoc.perl.org/functions/printf.html
http://perldoc.perl.org/functions/sprintf.html

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: undefined...

2005-05-21 Thread Offer Kaye
On 5/21/05, Ley, Chung wrote:
 Hi,
 
 I have a piece of code which generates array of arrays which then is used to 
 call the 
 GD::Graph::Boxplot...
 
 For some reasons, I would have elements that is defined but has not value.  I 
 have been 
 going thru the code to see if I had accidentally assigned null values or if I 
 had 
 accidentally do something like:
 data[0][1] = 1;
 data[0][100] = 100;
 without defining the 99 elements within the range; but it doesn't seem to be 
 the case
 

You can use the defined function to check if a value is 'undef or
not. Read perldoc -f defined from your command-line, or online at:
http://perldoc.perl.org/functions/defined.html

 Does someone has some suggestions as to how to debug this?
 

Debug what? Show us some code, explain exactly what you were expecting
and what the problem is, and *then* we can help.

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: foreach loop current index

2005-05-21 Thread Offer Kaye
On 5/21/05, Peter Rabbitson wrote:
 Hello,
 
 When perl executes a foreach loop, it creates some kind of array of all the
 iterators 

I'm assuming you mean that this code:
foreach my $num (1..1_000_000) {
   do_something($num);
}
creates a one-million number array? No, it doesn't, at least not in
current versions of Perl. Quoting perldoc perlop: In the current
implementation, no temporary array is created when the range operator
is used as the expression in foreach loops.

 and then goes over them one by one. Is the current index pointer
 accessible from inside the loop? I was unable to find anything related in
 perlvar.
 

Neither was I, but I suspect the reason is that if you need a counter,
you should not be using foreach. Instead, use for:
for(my $counter = 0; $counter  @array; ++$counter) {
  do_something_with($array[$counter]);
}

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Input template for data File

2005-05-20 Thread Offer Kaye
On 5/20/05, Craig Nock wrote:

 I would like to have this ?template? outside of my script, so this can
 change without the script changing (it will become an executable).
 I'm new to Perl and not sure of where to start looking for this
 functionality, and sure that someone else will have solved this problem


There are many templating systems used in Perl. New ones are
constantly being invented :-)
My favourite is HTML::Template -
http://search.cpan.org/dist/HTML-Template/Template.pm

Don't be alarmed by the HTML part, this is a general templating
solution, can be used for any problem where a template is needed.

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: XML

2005-05-19 Thread Offer Kaye
On 5/19/05, Scott Taylor wrote:
 
 ... to pump out lines of data to my SQL statement.
 
 I'll need to end up with something like:
 qw($vid,$eid,$event,$desc
   ,$date,$mid_desc,$mid_val
   ,$pid_desc,$pid_val,$min,$max,$val)
 
 for each line of data. (or whatever works)
 
 I think I'm just lost at the nested hash (if that's what it's called)
 thingy, and how to work with it. :|
 

It's a data structure, consisting of references to hashes and to arrays.
To begin with, start by reading tutorials such as:
http://perldoc.perl.org/perlreftut.html - references tutorial
http://perldoc.perl.org/perldsc.html - data structures cookbook

Once you've mastered the basics, you should be able to understand
these two statements:
$vid = $ref-{'vid'};
$pid_val = $ref-{'j1587'}-{'data'}-[0]-{'pid'}-{'val'};

These are just examples. To get at all the data in an organized way,
you'll need to wrap calls such as the above in loops-within-loops,
depending on how deep your data structure is.
Of course, after a while you might get tired of manually looping over
your data. In that case I suggest you start looking at XML modules
that provide OO access methods to your data, such as XML::SimpleObject
:
http://search.cpan.org/dist/XML-SimpleObject/SimpleObject.pm

That's just a suggestion, there are of course many others out there :-)

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Emulate tail -f on file

2005-05-19 Thread Offer Kaye
On 5/19/05, Tielman Koekemoer (TNE) wrote:
 
 Hi All,
 
 If I wanted to monitor a file in a way that would emulate tail -f
 (in the shell), how would I open the file?
 
 open(FILE,  filename |); (?)
 
 TIA
 

http://perldoc.perl.org/perlfaq5.html#How-do-I-do-a-tail--f-in-perl- 

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: using Mail::Sender

2005-05-19 Thread Offer Kaye
On 5/19/05, Graeme McLaren wrote:
 Hi all, I'm wanting to use the Mail::Sender module.  When sending emails
 I'll need to use an SMTP server.  On CPAN I found the following in the
 documentation, is this all I would need to send email?  What is the auth
 key for?  Surely all you need is a host, username and password?
 

If indeed you are using a login method (username and password), then
replace NTLM with LOGIN. So instead of:

auth = 'NTLM',

Use:

auth = 'LOGIN',

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: using Mail::Sender

2005-05-19 Thread Offer Kaye
On 5/19/05, Graeme McLaren wrote:
 Offer, everyone, I tried sending an email from a mail server and I got an
 error:
 
 Local user user unknown on host mail.smtpserver.com
 
 
 It seems to break on $email.  The user that the error reports is the value
 of $email, so why isn't it sending the email?
 
   from= '[EMAIL PROTECTED]',
   to  = $email,

According to http://search.cpan.org/dist/Mail-Sender/Sender.pm#AUTHENTICATION
: If you get a Local user [EMAIL PROTECTED] unknown on host zzz
message... it only accepts messages to or from a local user.
Maybe your server doesn't like '[EMAIL PROTECTED]' as a from
field? More likely, 'user' is not a valid email - try using a real
email address. I you want to use a name, the format is usually user
[EMAIL PROTECTED].

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: The last element

2005-05-08 Thread Offer Kaye
On 5/8/05, amr wrote:
 How can I call the last element in the array?
 
 I try the pop and it does the job but I think there is another way?
 

if the array is called @array, the last element can be called either using:
$array[$#array]
or
$array[-1]

Read:
http://perldoc.perl.org/perldata.html (everything about Perl data types)
http://perldoc.perl.org/perlintro.html (Perl Introduction - a great
beginner resource)

You can also read these from your command-line using the perldoc
command. Try perldoc perl.

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: seek(FH, 0,0) not working

2005-05-08 Thread Offer Kaye
On 5/9/05, N. Ganesh Babu wrote:
 Dear All,
 
 In the attached file, the date is present in the last line. My
 requirement is to capture the date and fill it in the date field from
 the line 1. after capturing the date through regular expression I am
 using seek(FH,0,0) to goto the beginning of the file. But it has no effect.
 

Your code will read the first line forever, since every time it will
read it, the next statement after the if' which is the seek (that is
missing the ; at the end BTW) will reset the position to the start
of the file.
1. You should move the seek inside the if.
2. Even after fix (1), your program will be stuck in an infinite loop,
since every time it will reach the last line it will jump right back
to the first line. Use a flag, condition or other mechanism to make
sure you loop through the file only one.

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How would I simulate this in Perl?

2005-05-06 Thread Offer Kaye
On 5/6/05, macromedia wrote:
 Hello,
 
 I have the following find/grep line running just fine from a telnet
 prompt on the server. I'm trying to include this line into a web app
 using CFEXECUTE (ColdFusion) but can't get it to work. I know that a
 compiled perl script would work since I'm already using some previously
 written ones.
 
 How could I do the following in Perl? I'm searing the directory
 d:\mywork and all sub-directories within for all the files with a .txt
 file extension and within those files for the match of 000;
 
 find D:\mywork -name '*.txt' -exec grep '000;' '{}' \; -print
 

You can use the File::Find module to do the same. I wasn't sure if
your above command also prints the matching lines or just the file
names, I assumed you also get a printout from grep. So something like
this (untested!) should work:
### begin code
use strict;
use warnings;
use File::Find;
find(\wanted, D:\mywork);
sub wanted {
   if (m/\.txt$/) {
  open(IN,$File::Find::name) or 
 die Couldn't open $File::Find::name for reading: $!\n;
  while(defined(my $line=IN)) {
 if ($line =~ m/000;/) {
print $File::Find::name : $line;
 }
  }
  close(IN) or 
 die Couldn't close $File::Find::name after reading: $!\n;
   }
}
### end code

Read the documentation of File::Find for more details about using this
module. You can read from your locally installed Perl documentation
(i.e. perldoc File::Find from the command line), or online at:
http://perldoc.perl.org/File/Find.html

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Writing my first perl script

2005-05-06 Thread Offer Kaye
 delimited by the curly braces which start
at line 14 and close at line 18. Read the following pages for details:
http://perldoc.perl.org/perlsyn.html (about the while flow control keyword)
http://perldoc.perl.org/functions/defined.html (about the defined function)
http://perldoc.perl.org/perlop.html#I-O-Operators (about the
FILEHANDLE construct)

* Line 15 - this time we want to match against the $line variable, not
$_, so we use the binding operator =~.Read:
http://perldoc.perl.org/perlop.html
for details. The RE itself is the simplest possible - a simple string

* Line 16 - finally, if the current file was a .txt file and the
current line matched the string 123, we print the string
$File::Find::name : $line to the file associated with the OUT
filehandle. For more about print read:
http://perldoc.perl.org/functions/print.html

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How would I simulate this in Perl?

2005-05-06 Thread Offer Kaye
On 5/6/05, macromedia wrote:
 
 I just tried it but get this error. What does it mean/
 
  perl test.pl
 Global symbol line requires explicit package name at test.pl line 18.
 Variable $line is not imported at test.pl line 19.
 Global symbol line requires explicit package name at test.pl line 19.
 Execution of test.pl aborted due to compilation errors.
 

It means you did something wrong :-)
The code I sent you doesn't have 19 lines, nor is there any problem
with it on my machine  - just tried it and the only problem is that I
should have used single quotes instead of double quotes in the path
arg to the find call, i.e.: 'D:\mywork'. instead of D:\mywork.

Did you perhaps change the code I emailed?

Could the problem be that you are using a very old perl? Please paste
the output of running perl -V from the command line. Also please
paste the exact contents of test.pl.

Regards,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: problem using regular expressions

2005-05-03 Thread Offer Kaye
On 5/3/05, Ing. Branislav Gerzo wrote:
 
 CDmy $address = '[EMAIL PROTECTED]';
 CDmy ( $domain  = $address ) =~ m/@(.*)/;
 
 uff, I think you write this in hurry, this simply won't work.

For completeness, you really should write what *will* work. Here's a
correct version:
   my $address  = '[EMAIL PROTECTED]';
   my ($domain) = $address =~ m/\@(.+)/;

And one more, using s/// instead of m// :
   my $address = '[EMAIL PROTECTED]';
   (my $domain = $address) =~ s/^.+?\@//;

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: REGEXP

2005-04-27 Thread Offer Kaye
On 4/27/05, [EMAIL PROTECTED] wrote:
 Please help me find the regexp to replace -o-b- - - -f
 thank you!
 

Replace it with *what*?

 s/sg//, s/\- {1,}(\w{1,})//,print +(split)[5,6,7], if (m/f01(\d+)/gi )
 

What does this code have to do with your question?

 my $_ has these lines in it:
 
 -o-b- - - -f
 F01045

Meaningless question subject, obscure question, some strange code and
data thrown in - it's like you don't *want* to get an answer ;-)

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: regex substitution

2005-04-27 Thread Offer Kaye
On 4/27/05, Ramprasad A Padmanabhan wrote:
 Hi all,
 
   I want a regex to replace all continuous occurrences of '-' with
 something else say 'x' except the first one
 

Here's one way:
   s/-(-+)/-.(xx length$1)/ge;

Explanation:
Flags: g means global, i.e. replace all occurences, and e means to
eval the replacement part as a perl expression and use the return
value as the replacement. Read perldoc perlop, the section on the
s/// operator, for mode details.
First part: -(-+) means to match a - sign followed by one or more
- signs, and save the - signs except for the first into $1. Note
that this means that single - signs will not be matches and
therefore affected at all.
Second part: returns a - (instead of the first, unsaved - we
matched in part one), concatanated (that's the .) with the char x
repeated length of $1 times (see perldoc perlop, section on
Multiplicative Operators for explanation of the x op, see perldoc
-f length for an explanation of the length function.

Some example code:
## begin code
use strict;
use warnings;
while (DATA) {
   chomp(my $orig = $_);
   s/-(-+)/-.(xx length$1)/ge;
   print $orig      $_;
}
__DATA__
bla
- Ram
-- bla
bla ---
-- blah ---
## end code
 
HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Hello

2005-04-27 Thread Offer Kaye
On 27 Apr 2005 11:34:21 -, laxmi goudappa patil wrote:
  Hello..
 Im new to the Perl..

Post some code, no one will be able to help you otherwise.
Also, Hello is a bad subject for an email to this list. Please use a
more meaningful subject in the future.

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Edit Windows PATH

2005-04-27 Thread Offer Kaye
On 1/1/88, amr wrote:
 Hi All,
 
 Do we have Perl script that can edit  add to the Windows (XP, 2000) path.?
 

The PATH environment variable can be accessed using the %ENV hash:
print $ENV{PATH};

You can change $ENV{PATH} in the script and it will change the PATH
for the rest of the script (and any sub-processes launched by it).

Someone else will have to help you if you want to change the system's
PATH, I don't know how to do that. Perhaps you should clarify what you
meant.

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Question about || (was REGEXP removing - il- - -b-f and - il- - - - f)

2005-04-27 Thread Offer Kaye
On 4/27/05, Peter Rabbitson wrote:
  also
  or die is more preferable than || die
 
 Why is that? :) 

It's a question of style, it is not better as in the code will work
better. It is mentioned in perldoc perlstyle that it is preferable
to use or and and instead of || and . However, see below for
an example of when || is actually better (IMO).

 I was actually going to post a question about ambiguity
 syntax later, but here it is anyway. Are the following 4 equivalent?
 
 1)
 if ($b) {
   $a = $b;
 }
 else {
   $a = $c;
 }
 
 2)
 $a = $b or $c;
 
 3)
 $a = $b || $c;
 
 4)
 $a = $b ? $b : $c;
 

Almost - 1 and 4 are too verbose, and 2 is just plain wrong. You have to write:
$a = ($b or $c);
Since the precedence of or is lower than =, if you write it
without the parens, you're actually writing:
($a = $b) or $c;
which will give you a warning under use warnings;. So in this case I
feel it is better to write:
$a = $b || $c;
Since in this case the || saves you the trouble of using parens and
the expression means exactly what you think it means. See perldoc
perlop for the precedence or Perl operatods.

 Also there was an example on the web that completely threw me off. Although
 this works:
 
 local ($/);
 
 ,I have no idea how it undefs $/. Points to a good reading on the
 subject are equally appreciated.
 

It declares $/ to be local without giving an init value. So now $/ has
the value of undef. This isn't specific to $/ - local will do the
same to any var:
use Data::Dumper;
our $foo = foo;
{
   local $foo;
   print Dumper($foo);
}
print Dumper($foo);

Read:
http://perldoc.perl.org/perlsub.html#Temporary-Values-via-local--

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Very basic question about running perl cgi on tomcat

2005-04-26 Thread Offer Kaye
On 4/25/05, Robert Kerry wrote:
 What should I do? Thank you.
 

You should use Google :-)
The first link returned by searching for Tomcat and Perl:
http://www.ftponline.com/javapro/2003_03/online/perl_teden_03_18_03/

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Some part of the text should not be converted

2005-04-26 Thread Offer Kaye
On 4/26/05, N. Ganesh Babu wrote:
 
 the above code is not working if the input is like this.   A Practical
 Guide to uCD-Rom/u and uDVD/u
 the output A Practical Guide to CD-Rom and CD-Rom
 

One way is to get the list of texts between the u and /u tag. I
choose to do it together with the substitution, using the e
modifier:
   my @un;
   $line=~s!u(.+?)/u!push @un,$1;u/u!ige;

After processing, put it back in using a for loop over the list of
saved texts, or an s///e construct:
   $line=~s!u/u!shift @un!ige;

Note the question mark in .+?. In reference to your question, yes,
you must use it, or the match will be greedy.
Personally I think you're workin too hard - you should be able to do
any processing on the line and not touch the the u delimited text,
without having to resort to removing it. But of course TIMTOWTDI :-)
Here is a complete working example:
## begin code
use strict;
use warnings;
while(defined(my $line=DATA)) {
   print '-' x 80 , \n;
   print Original line: $line;
   my @un;
   $line=~s!u(.+?)/u!push @un,$1;u/u!ige;
   #do something with line...
   print line after data removal: $line;
   # put back the data
   $line=~s!u/u!shift @un!ige;
   print line after data replace: $line;
}

__DATA__
A Practical Guide to uCD-Rom/u
A Practical Guide to uCD-Rom/u and uDVD/u
## end code

BTW, I would be happy if any of the gurus on the list could shorten:
   my @un;
   $line=~s!u(.+?)/u!push @un,$1;u/u!ige;
To a single line. Unlike m//, s/// never seems to return the
results of () in the RE, even in list context. Annoying :-(

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: core in perl??? i am not sure where to report this...

2005-04-26 Thread Offer Kaye
On 4/26/05, Manish Sapariya  wrote:
 [EMAIL PROTECTED] gdb /usr/bin/perl core.24670
 GNU gdb Red Hat Linux (5.2.1-4)

Read perldoc perlbug

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Number with More then 15 Digits.

2005-04-26 Thread Offer Kaye
On 26 Apr 2005 11:35:59 -, Govardhan M. V wrote:
  
 Hi
 
 $a = 1234567890123456789;
 printf (%0.0f\n, $a);
 
 Out Put is
 1234567890123456800
 
 which is wrong can any one let me know how do we handle
 Digits More than 15 digits ..
 

There is no wrong here. When trying to store a number larger than
the largest integer possible on your platform, perl converts to float.
Any C app compiled with the same compiler would do the same.
For details of when and which conversions take place, read perldoc
perlnumber. Anyway, you can use Math::BigInt to handle large
integers.

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Some part of the text should not be converted

2005-04-26 Thread Offer Kaye
On 4/26/05, N. Ganesh Babu wrote:
  Dear Offer Kaye,
  
  I want to preserve the u tag also in the context. Can you help me how to
 do it. If you run 2nd time also the same action will happen. If we remove,
 in the 2nd execution again the conversion will take place on these words.
  

Hi Ganesh,
I'm not following you - that do you mean context? What 2nd execution? 
Wild guess- you want the final line output from the code to include
the u tags? If so, simply use:
   $line=~s!(u.+?/u)!push @un,$1;u/u!ige;
So now the tags as well as the text are saved into @un and will appear
in the final output line.

Please read perldoc perlrequick, it will help you learn regular
expressions in Perl. You can read it online at:
http://perldoc.perl.org/perlrequick.html

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Re: Number with More then 15 Digits.

2005-04-26 Thread Offer Kaye
On 26 Apr 2005 13:35:27 -, Govardhan M. V wrote:
 
Hi,
  Thanks for the help,
  put i tried this 
  use Math::BigInt;
  $a = Math::BigInt-new(12345678901234567890);
  printf(%.0f\n,$a);
  
  out put is 
  12345678901234567168
  
  which is not right so please do let me know how do i go about it .
  My problem is in printing. can you let me  know how do i over come this
 issue.
  

Hi,
Please don't top post. Please don't use HTML emails. Please reply to the list.

With that out of the way, Depending on your needs, you can use %s as
the printf format string, or use simply print:
 begin code
use strict;
use warnings;
use Math::BigInt;
my $num = Math::BigInt-new(12345678901234567890);
print Orig string:   12345678901234567890\n;
printf printf output: %s\n,$num;
print print output:  $num\n;
 end code

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Configuration File generator

2005-04-25 Thread Offer Kaye
On 4/24/05, Tommy Nordgren wrote:
 I wan't links to any useful tools for generating configure scripts in
 perl.
 That is, tools to automatically generate the configure script for
 open-source
 C/C++ projects.
 

Perl itself uses a Configure script generated using the metaconfig
tool, which is (as best asI could find) poorly documented. See (if you
must):
http://search.cpan.org/dist/Config-Maker/
The Configure script itself can be seen here:
http://search.cpan.org/src/NWCLARK/perl-5.8.6/Configure

IMHO, for C and C++ projects, you are better off using the Automake
and Autoconf tools from the GNU Foundation:
http://www.gnu.org/software/automake/
http://www.gnu.org/software/autoconf/

Automake itself is written in Perl.

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Script that spans multiple files

2005-04-21 Thread Offer Kaye
On 4/21/05, Daniel Kasak wrote:
 Hi all.
 
 I have a large script ( 6000 lines ) that I'd like to break into logical
 units. Is there a way I can tell perl to 'append' a list of files into 1
 script so that I can call subs from any of the files and have them
 treated as if they were all from the same script ( ie all my variables
 will be visible )?
 

It's called a Perl Module, or .pm file. See:
perlmod Perl modules: how they work
perlmodlib  Perl modules: how to write and use
perlmodstylePerl modules: how to write modules with style

Brief example - say you have a module file called Foo.pm with the
following contents:
### begin Foo.pm contents
package Foo;
use Exporter qw( import );
@EXPORT_OK = qw(munge);  # symbols to export on request
use strict;
use warnings;
our $VERSION = '0.01';
sub munge {
   print This is a sub!\n;
}
1;
### end Foo.pm contents

Now in another script, say use_foo.pl, you write:
### begin use_foo.pl contents
use strict;
use warnings;
use Foo qw(munge);
print Foo::VERSION = $Foo::VERSION\n;
munge();
### end use_foo.pl contents

$VERSION is an example of a variable in Foo.pm accessible from an
external script, and munge() is an example of such a function.

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: WhiteSpace - Map, search replace, split

2005-04-21 Thread Offer Kaye
On 4/21/05, FreeFall wrote:
 Sure I did with Paul's example data :
   $date = 'one   |  two   |three  |';
 And I tried to change the regx /\s*\|\s*/ to /s*\|?\s*/ and it worked. What 
 do you think?

I think that's very strange. Here is my version:
 perl -MData::Dumper -we'use strict; my $date = q{one   |  two   |three  
 |};my @record = split /\s*\|\s*/,$date;print Dumper ([EMAIL PROTECTED]);'
$VAR1 = [
  'one',
  'two',
  'three'
];

Here is yours:
 perl -MData::Dumper -we'use strict; my $date = q{one   |  two   |three  
 |};my @record = split /\s*\|?\s*/,$date;print Dumper ([EMAIL PROTECTED]);'
$VAR1 = [
  'o',
  'n',
  'e',
  't',
  'w',
  'o',
  't',
  'h',
  'r',
  'e',
  'e'
];

As you can see, your version doesn't work correctly.

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Require / Use

2005-04-21 Thread Offer Kaye
On 4/21/05, Paul Kraus wrote:
 Why would one use Require instead of Use?
 

Because you want the action at run-time (require) vs. compile time
(use), is the usual reason, I would guess.

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: GetOpt::Long

2005-04-20 Thread Offer Kaye
On 4/20/05, Olivier, Wim W wrote:
 Hi all,
 
 Is it possible to use GetOpt::Long (or something similar) in a subroutine

Getargs::Long - 
http://search.cpan.org/dist/Getargs-Long/

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: WhiteSpace - Map, search replace, split

2005-04-20 Thread Offer Kaye
On 4/20/05, Paul Kraus wrote:
 Why does this work
 my $date = 'one   |  two   |three  |';
 my @record = map ( whitespace($_), (split /\|/,$_) );

No, it won't work - you need to replace the $_ at the end with $date

 sub whitespace {
   my $string = shift;
   $string =~ s/^\s+|\s+$//g;
   return $string;
 }
 
 but this does not 
 my @record = map ( $_=~ s/^\s+|\s+$//g,(split /\|/,$_) );
 

1. Again, the $_ at the end needs to be $date
2. This doesn't work because the s/// returns the number of
subtitutions made, not the string it changed, so that is what map gets
and passes (a list of numbers). See perldoc perlop for details. You
can use the block form of map, as follows:
my @record = map {s/^\s+|\s+$//g; $_} split /\|/,$date;
This works because the $_ statement at the end of the block now
constitutes the return value.
3. But there's an even easier way, without having to use map:
my @record = split /\s*\|\s*/,$date;

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Need help match feet and inches

2005-04-20 Thread Offer Kaye
On 4/20/05, Keith Worthington wrote:
 Hi All,
 
 Here is my code so far.  I am really getting frustrated with my inability to
 get this right.
 
 I didn't understand Chris' earlier suggestion about using defined but I tried
 using it anyway.
 
 I cannot seem to get the pattern match to properly handle a dimension that is
 just feet or just inches.
 
 I would really appreciate some pointers on this problem.
 

Hi Keith,
I assumed from your question that your main problem now is in handling
the size part ( what you called $v_size_str) and splitting it up into
4 parts - a first dimension feet and inches and a second dimension
feet and inches.
So here is some code to help you out. It doesn't break any of the
parts into sub-parts (e.g. 28-3/8 into the 3 numbers) but I assume you
can do that yourself. It also assumes you already have a variable
holding just the size part. For convenience (mine :-)), the code reads
from __DATA__ and assigns to $_ instead of $v_size_str, but you
shouldn't have any trouble modifing it. Here's the code:
# begin code
use strict;
use warnings;
while (DATA) {
   chomp;
   my ($dim1,$dim2) = split /\s*x\s*/i;
   print ==$dim1== ==$dim2==\n;
   my ($dim1_feet, $dim1_inches) = get_sub_dims($dim1);
   my ($dim2_feet, $dim2_inches) = get_sub_dims($dim2);
   print The sub-dims are: $dim1_feet, $dim1_inches, $dim2_feet,
$dim2_inches\n;
}
sub get_sub_dims {
   my $dim = shift;
   my ($feet, $inches) = (0,0);
   if ($dim =~ m/^\s*(.+?)'/) {
  $feet = $1;
  $dim =~ s/^\s*(.+?)'\s*//;
   }
   if ($dim =~ m/^\s*(.+?)/) {
  $inches = $1;
   }
   return ($feet, $inches);
}

__DATA__
9' x 25'
7'6 x 12'7
7'10 x 16'
83' X 40
17' x 50'
5' X 90'6
39 X 100
30 x 12'
28-3/8 x 14'4
16'  6-3/4 x 43
21'3 1/2 x 24'
14'8.5 x 16'7
# end code

If anything in the code isn't clear, please don't hesitate to ask.
HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Holidays

2005-04-20 Thread Offer Kaye
On 4/20/05, Robert [EMAIL PROTECTED] wrote:
 I need to populate a Pg database with holidays (US, Federal, Christian,
 Islamic, and Jewish). I didn't find anything on CPAN (but you have to know
 what to search for). The Islamic and Jewish ones are a little problematic
 because they can shift for year to year. Do you know of a resource I can
 look at?
 

I know of:
http://www.sadinoff.com/hebcal/
http://search.cpan.org/dist/Date-Holidays/

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: WhiteSpace - Map, search replace, split

2005-04-20 Thread Offer Kaye
On 4/21/05, FreeFall wrote:
  3. But there's an even easier way, without having to use map:
  my @record = split /\s*\|\s*/,$date;
 
 --this seems it cant delete spaces of the last element.
 

Have you tried it?

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Multiple programs output to separate log files + to STDOUT

2005-04-19 Thread Offer Kaye
On 4/19/05, Ambikesh Chaurasia wrote:
 Hi All,
 
 I am calling many C programs from my perl script. I want to log
 output of each of these C programs in DIFFERENT log files as well as
 I want to display this output to STDOUT.
 
 Please send me your sugesstion how to do this.
 
 Please note that I have already tried using
 1. IO::Tee:
  In this case, I get handle to tee, but I am not able to redirect
 the STDOUT to this handle.
 

What do you mean not able to redirect the STDOUT to this handle.?
Why not? What error did you get? did you try reading perldoc
IO::Tee? Here is a usage example, the part using IO::Tee was taken
almost directly from the EXAMPLES section:
# begin code
use strict;
use warnings;
use IO::Tee;
use IO::File;
my @progs = qw(prog1 prog2);
for my $program (@progs) {
   my $tee = new IO::Tee(\*STDOUT,
   new IO::File($program.log));
   print $tee `$program`;
}
# end code

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Match a pattern

2005-04-19 Thread Offer Kaye
On 4/19/05, lio lop wrote:
 I need to print the text between two words
   that are in different
 lines.
 

print \n;

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: mkdir? system? split?

2005-04-19 Thread Offer Kaye
On 4/19/05, JupiterHost.Net wrote:
 
 I'm not sure all those steps below are necessary. Have you looked at
   File::Copy::Recursive
 ?
 
 http://search.cpan.org/~dmuey/File-Copy-Recursive-0.06/Recursive.pm
 

There's also the mkpath function from File::Path, that can be used
to create a directory tree:
http://perldoc.perl.org/File/Path.html

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: What is the best way to release memory from data structure?

2005-04-19 Thread Offer Kaye
On 4/19/05, Ley, Chung wrote:
 Hi,
 
 I have a complex data structure using hash of hash of hash that I need to 
 hold one unit of 
 data that I need to process.  After finishing processing this unit, I need to 
 go to the 2nd 
 unit; each unit will be approx. 10Meg of data.
 
 What is the quick and efficient way for me to release the memory of the 
 previous unit 
 so that I can go and reuse it again?
 
 I tried a couple of following methods and neither seem to work  Please 
 let me know if I 
 am doing something wrong or should I take another approach...
 
 1. Just set the hash to empty
 my %datahash;
 while (moredetail) {
 $datahash{$level1}{$level2}{$level3}{$level4} = $something;
 }
 processdata(\%datahash);
 
 %datahash = ();
 

This doesn't release the memory? How do you know?
Have you tried using Devel::Size [1] to see the size of %datahash
after the release?
What about Devel::Monitor [2]?
What happens if you do as the release:
$datahash{$level1}{$level2}{$level3}{$level4} = ;
Does that help?

If all else fails, you might consider using tied hashes. Read:
http://perldoc.perl.org/functions/tie.html
and
http://perldoc.perl.org/Tie/Hash.html

[1] http://search.cpan.org/dist/Devel-Size/
[2] http://search.cpan.org/dist/Devel-Monitor/

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: sub declarations

2005-04-19 Thread Offer Kaye
On 4/19/05, M. Kristall wrote:
 
 If that doesn't help, definitely use perldoc.com :-) (if it's up).
 

See:
http://perldoc.perl.org/
Instead. It not only has a search box, it is even up :-)
You can also use Google to search it and ignore PDF files .Just type
in the google search box the following string:
search_term site:perldoc.perl.org -filetype:pdf

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Reading last 10 lines in file on Win32 Systems

2005-04-19 Thread Offer Kaye
On 4/19/05, Dave Adams wrote:
 I have a 2 gig log file and I need to read only the last 10 lines.
 
 I was also thinking something like:
 
 1. Read in File
 2. Get number of lines
 3. Print last ten lines
 
 or something like that.
 

On a 2gig file, that is very inefficient. Much better I think to use Tie::File:
# begin code
use strict;
use warnings;
use Tie::File;
my @array;
my $file = filename;
tie @array, 'Tie::File', $file or die Couldn't tie to '$file': $!\n;
for (reverse(1..3)) {
   print $array[-$_] . \n;
}
# end code
It is much faster because it doesn't read the entire file into memory,
or go over all of it just to get to the last 10 lines. Just be careful
- Tie::File lets you also modify the file, if you want. Read:
http://perldoc.perl.org/Tie/File.html
for more details.

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: regex lying to me

2005-04-19 Thread Offer Kaye
On 4/19/05, angie ahl wrote:
 The following regex is failing strangely:
 
 my @tables = $content =~ m#\[table\](.*?)\[/table\]#g;
 foreach (@tables) {
 my $table = $_;
 if ($content =~ m#$table#) {print yes old table is 
 there!\n;}
 }
 
 @tables contains 2 items (correctly) but seaching for each item in
 $content does not match.
 
 How can it find 2 matches and then claim that each of them aren't there?
 
 Perl 5.8.6 Mac OS X 10.3.8
 
 Thanks
 
 bemused Angie
 

Metachars in the results perhaps? Have you tried dumping @tables using
Data::Dumper and looking at the results?
Try using quotemeta (http://perldoc.perl.org/functions/quotemeta.html):
my $table = quotemeta;

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Capatalisation Question

2005-04-18 Thread Offer Kaye
On 4/18/05, N. Ganesh Babu wrote:
 Dear All
 
 I want to do capitalisation of this text. I am using the following code.
 It works fine with all other lines.
 
 $line=Level A (Grade 1 reading level);
 
 @words=split(/ /,$line);
 for($i=0;$i=$#words;$i++)
 {
 $words[$i]=~s!($words[$i])!\u\L$1!gi;
 print $words[$i]\n;
 }
 

Hi Ganesh,
There is a Perl builtin function called ucfirst that does what you
want (read perldoc -f ucfirst), but I also wanted to point out that
your code is very un-perlish. Specifically:

 @words=split(/ /,$line);
 for($i=0;$i=$#words;$i++)

There is no need to keep the result of split in a temporary array
(@words), nor iterate over the array using a c-style for loop.
Simple iterate over the results of the split:
for (split /(\s+)/, $line) { ...code... }
Inside the for loop (is actually a foreach loop, but the two
keywords are interchangable in Perl), the special variable $_ will
hold the current word returned by split.

If you look at my split usage, you will notice I wrote the pattern
/(\s+)/ inteead of / /. It is better to split of one or more
whitespace instead of on a single space, incase your string might
include something like word (two  spaces) word. Read perldoc -f
split for details.
In addition, I return the whitespace as part of the results, so that
the string will not look different (in terms of whitespace) when I
print it out. Here is the complete code:
## begin code
use strict;
use warnings;
my $line=Level A (Grade 1 reading level);
my $ucline = ;
for (split /(\s+)/,$line )
{
   $ucline .= ucfirst($_);
}
print $ucline\n;
## end code
Of course this means the ucfirst function will also operate on
whitespace, but this doesn't do any harm.

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Capatalisation Question

2005-04-18 Thread Offer Kaye
On 4/18/05, Jay Savage wrote:
 
 $line =~ /(\S+)/\u\L$1/g ;
 

Almost right - returns Level A (grade 1 Reading Level) - notice the
lowercase g in grade). Should be:
$line =~ s/(\w+)/\u$1/g;

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: error

2005-04-16 Thread Offer Kaye
On 4/16/05, Octavian Rasnita wrote:
 Hi,
 
 I have just install ActivePerl 5.8.6.8.11 under Windows 2000, and right
 after this, I have used the command:
 
 e:\usr\bin\perlivp.bat
 
 It gave the result below.
 Does this version of perl have some problems, or the perlivp.bat program
 is bad?
 
 Thank you.
 
 ok 1
 ok 2
 ok 3
 ok 4
 ok 5
 not ok 6
 # Perl header `stdio.ph' does not appear to be properly installed.

If you run perldoc perlivt.bat, you will see some helpful text, at
the bottom is:
 begin quote
* print # Perl header `$_' does not appear to be properly
installed.\n;
Correct by running h2ph over your system's C header files. If
necessary, edit the resulting *.ph files to eliminate perl syntax
errors.
 end quote

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Preventing CPU spikes / was switch confusion

2005-04-14 Thread Offer Kaye
On 4/14/05, David Gilden wrote:
 use strict;

Where is use warnings; ? It seems to be missing ;-)

 use switch;

Shouldn't that be use Switch; (with a capital S)?
Read perldoc Switch, the usage syntax is well documented there.

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: setting variable in certain cases

2005-04-14 Thread Offer Kaye
On 4/14/05, Jan Eden wrote:
 
 In example 1, I have to set the variable explicitly 5 times, in example 2, I 
 have to manually 
 list all cases outside the switch statement, which bears the risk of 
 forgetting to modify the 
 line once I extend the switch statement.
 
 So is there a better way to do it?
 

Why not use method #2 and use the @cases array for the actual case
statements? E.g.:
case ($cases[0]) {
   ...
   }

Note- the parens around $cases[0] are not optional, since this method
uses a variable as the first argument to case.

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Active Directory and Perl advice

2005-04-14 Thread Offer Kaye
On 4/14/05, Tim Wolak wrote:
 
 I am being asked to create a perl script to migrate AD accounts from one
 machine to another and also migrate their files and directory
 structure.  Is there any good web sites I can take a look for some
 example scripts or any good books?  Thanks in advance.
 

Google active directory perl (without the double quotes), you'll
find lots of good resources, e.g.:
http://www.rallenhome.com/books/adcookbook/code.html
http://isg.ee.ethz.ch/tools/realmen/det/adsi.en.html
http://www.perl.com/pub/a/2001/12/19/xmlrpc.html

HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Citation Parsing

2005-04-13 Thread Offer Kaye
On 4/13/05, N. Ganesh Bab wrote:
 
 The main feature in this module is matching templates. Already this
 module is having 400 templates. But in all the templates, It is parsing
 only one author information. It is leaving the rest of the authors.
 

Are you sure about this? Are you using:
   my @authors = Biblio::Citation::Parser::Standard::handle_authors($string);
or something else?

 Can anybody modify the Standard.pm which is inside this module to take
 care of multiple authors.

This question probably be sent to the author of the module, either
directly or through the RT system.

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Searching for embedded EOF in binary

2005-04-13 Thread Offer Kaye
On 4/13/05, Jay Savage wrote:
 
 I'm thinking now that I should probably just take what I can get from
 the recovery I have, and postprocess the recovered files, instead of
 trying to get the recovery itself to be clean.
 

Silly question probably, but why don't you take everything from one
$magic to the next, if you assume multiple jpegs in one file, instead
of looking for the EOI (since you can't find it)? Each such block will
then be, I assume, a (possibly corrupt) jpeg.

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Searching for embedded EOF in binary

2005-04-13 Thread Offer Kaye
On 4/13/05, Jay Savage wrote:
 Hi, all:
 
 Below is a script to extract jpegs from an image of a corrupted or
 accidentally erased CF or other removable media from a digital camera.

Here's another one, found by Googling. Maybe it will help:
http://www.zinkwazi.com/tools/jpg-recover

-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Is this allowed?

2005-04-07 Thread Offer Kaye
On Apr 7, 2005 6:33 AM, Bill Evans wrote:
 
 In this scenario, I have a text file, the first line of which contains a bank 
 account number and 
 opening balance. The second line contains records of checks drawn on the 
 account. The last 
 line contains a zero amount. Im trying to code a script that will read and 
 print to a file the 
 account number, opening balance and check records. In addition I wish that 
 the current balance 
 is displayed along with the check records (a running balance).
 

Hi,
The first problem in your code is that you don't use use strict; and
use warnings; in your code. This causes you not to catch many other
errors, such as having the line:
   $line = readline(INPUT);
but INPUT is not defined anywhere, or:
   $totalafterfirst = $noopbal[3] - $cheques[1];
but @cheques is not defined (you used @checks in other places).

Other then that, you are almost okay, but the code you used to
calculate the running balance is too complex. Think of this
psuedo-code:

foreach check
balance = current balance minus check amount
print balance
end for loop

This can be translated almost as is to Perl code. Here is a version
that works, and that also includes some prettying up of your code,
such as combining the arguments to print into one string:
 begin code
use strict;
use warnings;
my $infile = bank.txt;
open(TEXT, $infile) || die(Cannot find file: $! !\n);
open(OUTPUT, report.txt) || die (Cannot open output file: $! !\n);
my $line = TEXT;
my @noopbal = split(/!/, $line);
print The Account Number is $noopbal[1]\n;
my $balance = $noopbal[3];
print The opening balance of this account was $balance\n;
print Printing report to file...\n;
print(OUTPUT Statement of account report\n\n);
print(OUTPUT Acc Number: $noopbal[1]\n);
print(OUTPUT Opening Balance: $noopbal[3]\n\n);
$line = TEXT;
my @checks = split(/\@/, $line);
# get rid of empty last and first elements:
shift @checks; pop @checks;
print(OUTPUT Cheque Debits  @checks\n);
print(OUTPUT Current Balance: );
for (@checks) 
{
   $balance -= $_;
   print(OUTPUT $balance );
}
print(OUTPUT \n);
 end code

-- 
Offer Kaye

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: a module query

2005-04-06 Thread Offer Kaye
On Apr 6, 2005 2:33 PM, Manish Sapariya wrote:
 Hi List,
 Can somebody throw some light on what the following
 code snippet is doing...
 
 ==
 @Utils::ISA = qw(Exporter);
 @Utils::EXPORT = qw(set_verbose vprint logmsg
 convert_size ip2int int2ip
 time2str);
 ===
 
 EXPORT if I gues correctly, is exporing the functions
 listed in the modules.
 
 But then why would one need to export them explicitly.
 

Because if functions were exported automatically, they would pollute
the namespace of the calling script. Read:
http://perldoc.perl.org/Exporter.html

 I dont have any clue whats the significance of ISA.
 
 What perldoc shall I see for help on this?
 

Start here for ISA info:
http://perldoc.perl.org/perlboot.html#A-few-notes-about--ISA
Then read this:
http://perldoc.perl.org/perlobj.html#A-Class-is-Simply-a-Package

HTH,
-- 
Offer Kaye

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Converting a retruned string value to a number

2005-04-06 Thread Offer Kaye
On Apr 6, 2005 5:17 PM, Manish Sapariya wrote:
 Hi List,
 How do i convert a string variable returned by
 some XPath API into a number so that I can
 compare it or loop using this number.
 
 I am reading one number from XML and I want to
 use it for looping.
 

In general, conversion from a string to a number is transparent in
Perl. 4 is the same as 4.

HTH,
-- 
Offer Kaye

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: initialize arrays

2005-04-05 Thread Offer Kaye
On Apr 5, 2005 4:29 PM, Larsen, Errin M HMMA/IT wrote:
 
 Hi everyone,
 
   this one made me wonder.  Isn't there a way to get Perl to print out
 exactly how it evaluates the statements that are written?  

Sure - the B modules, such as B::Debug and B::Concise.

 If so, we
 could use that to see what Perl does with those two different
 assignments above.
 

Seeing is one thing; understanding - that's quite another thing ;-)

-- 
Offer Kaye

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Regular expression $1,$2,$3 ... in array ?

2005-04-05 Thread Offer Kaye
On Apr 5, 2005 5:53 PM, Michael Gale wrote:
 
 So two questions,
 
 1. I can simplify the above regexp by using groups correct ?
  /output:.*DISK.*-.free.space:(.(\S+).*MB.\((\d+)%\):){1,}/
 

Yes, you can simplify by using groups, but there's something wrong
with both your REs, IMHO. What exactly are you trying to capture from
the data? Your RE looks too complex to me. I think you are trying to
get the path name and percentage number, right? Well, here's one way:
   /(\/\S*).+?\((\d+)/sg
Note the s modifier - your data is multiline, so I need the s
modifier to make . match a newline.

 2. It breaks it up into parts, $1,$2,$3,$4,  etc. Can I save the
 parts into an array ?

Simply assign the result of the match to an array:
my @arr = /(\/\S*).+?\((\d+)/sg;

-- 
Offer Kaye

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Lost here.. Use of uninitialized value in print?

2005-04-04 Thread Offer Kaye
On Apr 4, 2005 2:42 PM, [EMAIL PROTECTED] wrote:
 
 Using use strict; I end up with a range of warnings, I don't know how
 relevant they are here. Thanks again.
 

Those aren't warnings, they are errors - your program is not compiling
correctly. You need to place a my in front of your variables when
you declare them (not when you use them) when you use strict.

Originally, your problem is here:
$list1 = @rawtext;
This simply puts the number of items in the array @rawtext (i.e. the
number of lines of the input file) into the scalarvariable $list1.
What were you trying to do?

-- 
Offer Kaye

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Frustration - split not working as expected

2005-04-01 Thread Offer Kaye
On Apr 1, 2005 12:45 PM, Brett Williams wrote:
 Im aware of regular
 expressions now, but find them too confusing at this stage (im an
 extreme newbie to any programming).

Read perldoc perlrequick (type that into your terminal), that will
get you up to speed quickly regarding regular expressions. You can
also read it online:
http://perldoc.perl.org/perlrequick.html

 
 I want to print to screen all text between : on a new line. I
 thought this would be easy :)
 The final code i came up with is,
 

First comment - always start your code with:
use strict;
use warnings; 
It will help you tremendously, especially as a beginner.

 open (INPUT, file.txt) or die Error, can't find file\n;

Good job, however the error message is a little slim. See my code, below.

 $line = readline(INPUT);
 while($line)

There's no real reason for you to use readline here - much better
(less typing :-)) to use the diamond operator. See my code below.

 {
 chomp($line);

chomp removes the \n from the input line. Why are you doing this
here? Since you are already splitting the input line, that will get
rid of the \n - chomp is redundant here.

 @pricelist = split (/\:/, $line);

No need to escape the :, it is not a metacharacter.

 
 For some reason this code prints out the entire contents of the text
 file (and fails to display every entry on a new line). Im completely
 lost, can anyone help?
 

Here's some code that works. I explain it below:
# begin code
use strict;
use warnings;
my $infile = file.txt;
open (INPUT, $infile) or die $0 error, can't open $infile for reading: $!\n;
while(defined (my $line = INPUT))
{
   my @pricelist = split (/:/, $line);
   print $pricelist[1]\n if @pricelist != 1;
}
close(INPUT);
# end code

As you can see, I started with use strict and use warnings. 
The open line is essentially the same as yours, I simply beefed-up
the error message (read perldoc perlvar for more info about $0 and
$!).
There is no need to assign to $line outside the while loop - you can
do so inside the while itself. The code I wrote uses a common idiom,
that checks if the value of the assignment is defined. The value will
not be defined at the EOF, at which point the while will be exited.
Just what we need :-)
'print $pricelist[1]\n if @pricelist != 1;' says that if the number
of elements in the array @pricelist is not 1, print something. Why is
that? Well, looking at the input, I saw that unwanted lines will have
no : in them at all. The result of split from an unwanted line wil
have just 1 result (@pricelist==1), since split on /:/ will basically
return the entire line - there is nothing to split. So lines for which
@pricelist != 1 must be wanted lines.
$pricelist[1] is the second element of the array @pricelist. If you
need to know more, read perldoc perlintro, it is a very good
introduction to Perl's syntax, variables, etc. The reason the number
we want is in the second and not first element has to do with the way
split works. You can read about split at perldoc -f split, just as
you can read about any Perl function using perldoc -f
function_name. I'll let you figure out exactly what split is
doing here be yourself :-)

Hope this helps,
-- 
Offer Kaye

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Frustration - split not working as expected

2005-04-01 Thread Offer Kaye
On Apr 1, 2005 6:39 PM, Charles K. Clarkson wrote:
 
 Using a \n after the $! variable suppresses information about
 the error. 

Correction - the \n doesn't suppress the information because it
comes after the $! variable - it has nothing to do with it. This
behaviour is due to die. From perldoc -f die:
   If the last element of LIST does not end in a newline,
the current script line number and
   input line number (if any) are also printed, and a
newline is supplied.

Hope this helps,,
-- 
Offer Kaye

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: quick regex question

2005-03-31 Thread Offer Kaye
On Thu, 31 Mar 2005 02:08:22 -0800, John W. Krahn wrote:
 
 $ perl -le'
 my $str = q/[EMAIL PROTECTED]/;
 $str =~ s/([EMAIL PROTECTED])/($a = $1) =~ tr|_|.|; $a/e;
 print $str;
 '
 [EMAIL PROTECTED]
 
 $ perl -le'
 my $str = q/[EMAIL PROTECTED]/;
 substr( $str, index $str, q/@/ ) =~ tr/_/./;
 print $str;
 '
 [EMAIL PROTECTED]
 

Nice!
Here are 2 other methods, just for the heck of it :-)
# Method 1
my $str = '[EMAIL PROTECTED]';
my ($part1,$part2) = split /@/, $str;
$part2 =~ s/_/./g;
$str = $part1.@.$part2;
print $str\n;

# Method 2
my $str = '[EMAIL PROTECTED]';
while ($str =~ m/(?=@).+?_/) {
   $str =~ s/(?=@)(.+?)_/$1./;
}
print $str\n;

Ram, there is just one thing you should notice - in your question, you
double-quote the string you assign to $str. You can't do that, because
the  perl tries to evaluate the @lmn_p_q part as the name of an array.
So you either have to single quote the string (as John and I did) or
escape the @ sign with a backslash:
   my $str = [EMAIL PROTECTED];

Hope this helps,
-- 
Offer Kaye

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: apache log parsing

2005-03-31 Thread Offer Kaye
On Thu, 31 Mar 2005 13:24:24 +0200, John Doe wrote:

 [2] use another delimiter (don't know the english term at the moment)


Delimiter is the correct term.
See perldoc perlop, the beginning of the section titled Quote and
Quote-like Operators.

-- 
Offer Kaye

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Question: Array of Hashes

2005-03-31 Thread Offer Kaye
On Thu, 31 Mar 2005 14:40:47 +0200, Olivier, Wim W wrote:
 Hi all,
 
 I have the following code below which I need to modify a bit.
 
 The script currently lists the key/value pairs for all processes in the
 system.
 What I need to achieve is for it to only list the key/value pairs for
 processes of which the Description key is of a certain ASCII value, say
 analytics.exe.
 

Untested, but here goes:
foreach my $info (@info)
{
   if ($info-{'Description'} eq analytics.exe) 
   {
  foreach ('ProcessId', 'Description', 'ThreadCount')
  {
 print $_ = , $info-{$_} || '', \n;
  }
  print \n;
   }
}

Hope this helps,
-- 
Offer Kaye

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




  1   2   >