Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-14 Thread Jerry Rocteur
Hi,

I'm trying to be a good boy and use strict and warnings ..

The more I do, the more I feel I'm wasting so much time and should 
become productive, my code looks full of 'my', I could understand the 
requirement inside a sub routing but in the main code it gives me the 
willies. My DBI Perl is even more of a headache ;-((

Anyway, enough whining, now I've going through code that is working and 
thought I'd see the big difference if I change it to use warnings and 
strict and this little routing gives me  'Use of uninitialized value in 
pattern match (m//) at ./getopt.pl line 14.'

Line 14 is the while line..

I've tried all sorts of stuff with defined but keep getting syntax 
errors. I've tried perldoc warnings and perldoc perllexwarn .. In any 
case, unless I'm really missing something, I can't see what could be 
problematic with the while statement below, of course this shows my 
ignorance but as I've decided to use warnings and strict, I want to do 
it right..

How would a pedant code the following to avoid this warning.. Your 
answers will help me in the future.

#if ($#ARGV >= 0) { # What I've tried
while ($_ = $ARGV[0], /^-/) {
shift;
last if /^--$/;
if (/^-d(.*)/) { $debug++ }
elsif (/^-v(.*)/) { $verbose++ }
else { print "$_ unknown option\n";
Usage;
}
}
#}
Thanks in advance, I really want to put, Perl with warnings and strict 
in my CV ;-

Jerry

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Parentheses

2003-12-14 Thread Steve Grazzini
[ Remailed to the list (sorry about that, Rob) ]

On Dec 13, 2003, at 9:07 AM, Rob Dixon wrote:
As a final thought, I would point out that $_ is a package ('our')
variable, but is localised by 'map', 'grep', 'foreach (LIST)' and
'while (<>)'.
Actually, $_ isn't localized by 'while(<>)':

% echo test | perl -le 'for ("const") { print while <> }'
Modification of a read-only value attempted at -e line 1.
Which occasionally jumps up and bites people.

And for the trivia buffs: another interesting thing about the special
package variables (it's the globs/symbols that are actually special,
see below) is that they're always in package "main".
% perl -le '{ package X; $inc++ } print "[$inc]"'
[]
% perl -le '{ package X; $INC++ } print "[$INC]"'
1
The exception to this is when an our() declaration (which is a
lexically scoped symbol, remember) hides the special global.
% perl -le '{ package X; our $INC = 1 } print "[$INC]"'
[]
--
Steve
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Getting the most recent file

2003-12-14 Thread Paul Harwood
One question I have:

With this statement: 

@files = sort { -M $a <=> -M $b } @files;

How does Perl understand that these are files and not just text entries?
Did using the readdir beforehand make this possible?

-Original Message-
From: Rob Dixon [mailto:[EMAIL PROTECTED] 
Posted At: Saturday, December 13, 2003 6:27 AM
Posted To: Perl
Conversation: Getting the most recent file
Subject: Re: Getting the most recent file

<[EMAIL PROTECTED]> wrote:
>
> I am trying to write some code to read the most recent log file in a
> directory. I wrote some code below. This works but I was wondering if
> there was a more efficient method to do this. Ideally I would like to
> include hours, minutes and seconds but that's not necessary at this
> point.
>
> foreach $iislog (@files) {
>
>   ($WRITETIME) = (stat("$iislogs\\$iislog"))[9];
>
>   print scalar localtime ($WRITETIME);
>
>   ($seconds, $minutes, $hours, $day, $month, $year, $wday, $yday,
$isdst) = localtime();
>   ($seconds2, $minutes2, $hours2, $day2, $month2, $year2, $wday2,
$yday2, $isdst2) = localtime($WRITETIME);
>
>   if ($day == $day2 && $month == $month2) {
>
> print "\n\n";
> print "The file was last modified on: ";
> print scalar localtime ($WRITETIME);
> print "\n\n";
>   }
> }

Hi Paul.

First of all,

  use strict;   # And declare all of your variables
  use warnings;

# And indent your code!

Then I'm not sure what you need. You say you want to read the most
recent log file,
but your code just prints out a list of modification times. Do you need
this
as well,or do you just want to find the latest file?

  (stat $file)[9]

gives you the modification date, while

  -M $file

gives you the age of the file. So you could just write

  @files = sort { -M $a <=> -M $b } @files;
  print $files[-1], "\n";

Or do you need anything more?

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Split question

2003-12-14 Thread Josimar Nunes de Oliveira
Try this:

@temp = split('\#', "abc#def#ghi#jkl") ;
foreach (@temp){
 print "\n", $_;
}

Josimar

- Original Message - 
From: "Perl" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, December 14, 2003 3:16 AM
Subject: Split question


> Hi,
>i am new to Perl.
>here is my question 
> 
>   i have a character string like abc#def#ghi#jkl
> 
>   i want to split the string based on the delimiter # so that i get 
> something like this :
> 
>   abc  def  ghi jkl
> 
>   But
>   
>   @temp = split(/#/, "abc#def#ghi#jkl") ;
> 
> doesn't seem to work.
> 
> am i doing anything wrong here ?
> 
> thanks,
> S.
> 
> 
> 
> 
> 
> -
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-14 Thread Jerry Rocteur
On Saturday, Dec 13, 2003, at 18:12 Europe/Brussels, Jerry Rocteur 
wrote:

Hi,

I'm trying to be a good boy and use strict and warnings ..

The more I do, the more I feel I'm wasting so much time and should 
become productive, my code looks full of 'my', I could understand the 
requirement inside a sub routing but in the main code it gives me the 
willies. My DBI Perl is even more of a headache ;-((

Anyway, enough whining, now I've going through code that is working 
and thought I'd see the big difference if I change it to use warnings 
and strict and this little routing gives me  'Use of uninitialized 
value in pattern match (m//) at ./getopt.pl line 14.'

Line 14 is the while line..

I've tried all sorts of stuff with defined but keep getting syntax 
errors. I've tried perldoc warnings and perldoc perllexwarn .. In any 
case, unless I'm really missing something, I can't see what could be 
problematic with the while statement below, of course this shows my 
ignorance but as I've decided to use warnings and strict, I want to do 
it right..

How would a pedant code the following to avoid this warning.. Your 
answers will help me in the future.

#if ($#ARGV >= 0) { # What I've tried
while ($_ = $ARGV[0], /^-/) {
shift;
last if /^--$/;
if (/^-d(.*)/) { $debug++ }
elsif (/^-v(.*)/) { $verbose++ }
else { print "$_ unknown option\n";
Usage;
}
}
#}
Thanks in advance, I really want to put, Perl with warnings and strict 
in my CV ;-

Jerry




Sorry for the double post, my first post I had done with an email 
address that is not subscribed to the list, thinking it would not go 
through I reposted. I didn't realize you accepted posts from non 
subscribed addresses.

I thank all those that replied on and off list, great replies. Of 
course my question was more than answered.  Thanks to Wigins d'Anconia, 
Rob Dixon, R. Joseph Newton and drieux! Food for thought.  I'm still 
reviewing your replies..

Best Regards,

Jerry Rocteur

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Getting the most recent file

2003-12-14 Thread Rob Dixon
Paul Harwood wrote:
>
> One question I have:
>
> With this statement:
>
> @files = sort { -M $a <=> -M $b } @files;
>
> How does Perl understand that these are files and not just text entries?
> Did using the readdir beforehand make this possible?

Well they /are/ just text entries! But ones that correspond to the names
of existing files. Strictly speaking it's possible for a file to have been
deleted between cataloguing it with 'readdir' and sorting the list,
but this will just give you a warning (if you have 'use warnings' set)
and sort the vanished file as if it had an age of zero days. If your
software is at all permanent then you can temporarily switch off that
particular warning by putting the statement in a block like this:

  {
no warnings 'uninitialized';
@files = sort { -M $a <=> -M $b } @files;
  }

(After that, you should really cope with the condition where /all/
of the files have been deleted in the interim so thet even the
oldest file doesn't exist :)

You also need to be aware that, unless the directory listing is
of your current directory each element needs to be prefixed with
the full path.

HTH,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Parentheses

2003-12-14 Thread Rob Dixon

Steve Grazzini wrote:
>
> On Dec 13, 2003, at 9:07 AM, Rob Dixon wrote:
> > As a final thought, I would point out that $_ is a package ('our')
> > variable, but is localised by 'map', 'grep', 'foreach (LIST)' and
> > 'while (<>)'.
>
> Actually, $_ isn't localized by 'while(<>)':
>
>  % echo test | perl -le 'for ("const") { print while <> }'
> Modification of a read-only value attempted at -e line 1.
>
> Which occasionally jumps up and bites people.

Thanks for that Steve. I guess if you think about it then,
since it's equivalent to the awful

  while (defined($_ = <>)) {
:
  }

it's actually not a loop control variable at all, but an explicit
assignment to $_.

> And for the trivia buffs: another interesting thing about the special
> package variables (it's the globs/symbols that are actually special,
> see below) is that they're always in package "main".
>
>  % perl -le '{ package X; $inc++ } print "[$inc]"'
>  []
>  % perl -le '{ package X; $INC++ } print "[$INC]"'
>  1

Yes, but what I find most surprising is that $INC is $main::INC
even though @INC and %INC are special variables but $INC isn't :)

> The exception to this is when an our() declaration (which is a
> lexically scoped symbol, remember) hides the special global.
>
>  % perl -le '{ package X; our $INC = 1 } print "[$INC]"'
>  []

Yes, because this is the same as

  perl -le "$X::INC = 1; print qq/[$INC]/"

I wonder if you, or anybody, knowswhere the localisation of $_
is documented? My Camel was 'borrowed' and feeling rather lonely.

Thanks,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Parentheses

2003-12-14 Thread Rob Dixon
R. Joseph Newton wrote:
>
> Rob Dixon wrote:
>
> > > foreach (@lines) {
>
> #  too many lines here
>
> > > }
> > >
> > > While the purpose of the above may bve totally
> > > incomprehesible, there is no question about what $_ is.  <;:-o)
> >
> > One proviso here. I always feel very uncomfortable about
> > explicitly assigning to $_. As I implied in my post to
> > Wiggins, $_ is very much the equivalent to 'it', and I would
> > no more use 'it' over more than a simple English sentence
> > than I would use $_ across nested loops, procedure calls or
> > whatever. In English your lines above say
>
> You're right.  I actually got carried away.  I was having so
> much fun coming up with the most pointless code possible. that
> I forgot the main point.  The use of the idefault $_ did serve
> its purpose, though, perverse as it was.  I should probably
> have done the print outside the loop to demonstrate both the
> purpose and danger of using "it":
>
> my @lines = ();
>
> foreach (@lines) {
>chomp;
>s/dog/cat/g;
>my @words = split;
>$words[0] = lc $words[0];
>$_ = join ' ', reverse @words;
> }
>
> print"$_\n" for @lines;
> #same data, results as previous sample
>
> ...has the same effect as printing from inside the loop.
> Which means that my array contents
>
> have either been effectively modified, or totally hashed,
> depending on whether that was the desired effect.

..except that, to be picky, you need

  print ucfirst "$_\n" for @lines

outside the loop. And that this is a warning for 'foreach'
in general, not specifically for $_. If your loop had been

  foreach my $line (@lines) {
:
  }

then the named scalar would similarly have been aliased
with the array elements.

Cheers,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-14 Thread Bakken, Luke
> uninitialized value in 
> pattern match (m//) at ./getopt.pl line 14.'
 
Use the standard Getopt::Std module to process options. Don't do it
yourself.

> Line 14 is the while line..
> 
> I've tried all sorts of stuff with defined but keep getting syntax 
> errors. I've tried perldoc warnings and perldoc perllexwarn .. In any 
> case, unless I'm really missing something, I can't see what could be 
> problematic with the while statement below, of course this shows my 
> ignorance but as I've decided to use warnings and strict, I 
> want to do 
> it right..
> 
> How would a pedant code the following to avoid this warning.. Your 
> answers will help me in the future.
> 
> #if ($#ARGV >= 0) { # What I've tried
>  while ($_ = $ARGV[0], /^-/) {
>  shift;
>  last if /^--$/;
>  if (/^-d(.*)/) { $debug++ }
>  elsif (/^-v(.*)/) { $verbose++ }
>  else { print "$_ unknown option\n";
>  Usage;
>  }
>  }
> #}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




list problem

2003-12-14 Thread km
Hi all,

when i use  range operator in foreach loop it increases the elements in the list by 
one.
for eg : 
foreach(1..10)
{
print;
}
#prints  1,2,3,4,5,6,7,8,9,10

but if i need to set a hop for each number how do i get it ? something like stride 
functionality  so that it will print 1,4,7,10 
something like 

for(1..10 ,jump 3)
{
print; 
}

kindly  enlighten ,

thanks,
KM

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Parentheses

2003-12-14 Thread R. Joseph Newton
Rob Dixon wrote:

> R. Joseph Newton wrote:
> >
> > Rob Dixon wrote:
>
> > ...has the same effect as printing from inside the loop.
> > Which means that my array contents
> >
> > have either been effectively modified, or totally hashed,
> > depending on whether that was the desired effect.
>
> ..except that, to be picky, you need
>
>   print ucfirst "$_\n" for @lines

Yep

> outside the loop. And that this is a warning for 'foreach'
> in general, not specifically for $_. If your loop had been
>
>   foreach my $line (@lines) {
> :
>   }
>
> then the named scalar would similarly have been aliased
> with the array elements.
>
> Cheers,
>
> Rob

Ouch!  Thanks for the heads-up!  That is downright scary.  Strangely
enough, I don't think I have ever been bitten by that in actual coding.
Maybe this is a good argument for the approach I alluded to earlier in
the thread, of assigning the value of the it variable to a named scalar
first thing inside the loop.  Geez, now I'll have to scan through my old
code and see how I have been hamdling this and keeping data intact.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: list problem

2003-12-14 Thread John W. Krahn
Km wrote:
> 
> Hi all,

Hello,

> when i use  range operator in foreach loop it increases the
> elements in the list by one.
> for eg :
> foreach(1..10)
> {
> print;
> }
> #prints  1,2,3,4,5,6,7,8,9,10
> 
> but if i need to set a hop for each number how do i get it ?
> something like stride functionality  so that it will print 1,4,7,10
> something like
> 
> for(1..10 ,jump 3)
> {
> print;
> }
> 
> kindly  enlighten ,

You have to use a C style for loop like this:

for ( local $_ = 1; $_ <= 10; $_ += 3 ) {
print;
}



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: list problem

2003-12-14 Thread Fred Nastos
On December 14, 2003 01:21 pm, km wrote:
>
> but if i need to set a hop for each number how do i get it ? something like
> stride functionality  so that it will print 1,4,7,10 something like
>
> for(1..10 ,jump 3)
> {
> print;
> }

How about the old-fashioned way?

for ($i=1; $i<=10) {
print $i, "\n";
$i = $i + 3;
}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Split question

2003-12-14 Thread John W. Krahn
Josimar Nunes De Oliveira wrote:
> 
> From: "Perl" <[EMAIL PROTECTED]>
> >
> >   @temp = split(/#/, "abc#def#ghi#jkl") ;
> >
> > doesn't seem to work.
> >
> > am i doing anything wrong here ?
> 
> Try this:
> 
> @temp = split('\#', "abc#def#ghi#jkl") ;
> foreach (@temp){
>  print "\n", $_;
> }

The first argument to split is converted to a regular expression and the
'#' character is not special in a regular expression so split/#/ and
split'\#' do exactly the same thing.



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-14 Thread Owen
On Sat, 13 Dec 2003 18:12:17 +0100
Jerry Rocteur <[EMAIL PROTECTED]> wrote:

> I'm trying to be a good boy and use strict and warnings ..
> 
> The more I do, the more I feel I'm wasting so much time and should 
> become productive, my code looks full of 'my'


Because so many people in c.l.p.m said "use strict;" I decided to take the plunge and 
use it.

Until I worked out what was going on, I, like you, thought it was a waste of time.

That and warnings are a great pair in getting programs to run and I suppose "Use of 
unitialized..." is the most common warning. There is always a bit of pleasure in 
tracking down the reason for that one.

See http://perl.abigail.nl/Musings/coding_guidelines.html suggested perl coding 
practices
 
Hang on in there, it's worth it. 




-- 
Owen


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: list problem

2003-12-14 Thread John W. Krahn
Fred Nastos wrote:
> 
> On December 14, 2003 01:21 pm, km wrote:
> >
> > but if i need to set a hop for each number how do i get it ? something like
> > stride functionality  so that it will print 1,4,7,10 something like
> >
> > for(1..10 ,jump 3)
> > {
> > print;
> > }
> 
> How about the old-fashioned way?
> 
> for ($i=1; $i<=10) {
> print $i, "\n";
> $i = $i + 3;
> }

That produces a syntax error, it won't run.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Question for this Group ... dont flame me :)

2003-12-14 Thread Jenda Krynicky
From: Jeff Westman <[EMAIL PROTECTED]>
> Guay_Jean-Sébastien <[EMAIL PROTECTED]> wrote:
> > b) As new need arises in your program, using a module gives you
> > access to other functionality which you would have to (again) write
> > yourself if you were not unsing a module.
>
> But would you agree, that at least in some cases, it is "almost" as
> hard to use and understand a CPAN module then to write your own?  Some
> of the documentation out there isn't the greatest :)

Then everyone will be really gratefull if you send some doc patches!

If you spent a lot of time trying to figure out what does the module
du, write your findings down, rewrite the docs and send them to the
author. Some good coders are horrible documentors (and they usualy
know it about themselves) so do make the life easier for those that
come after you.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Split question

2003-12-14 Thread Joel Newkirk
On Sun, 2003-12-14 at 14:52, John W. Krahn wrote:
> Josimar Nunes De Oliveira wrote:
> > 
> > From: "Perl" <[EMAIL PROTECTED]>
> > >
> > >   @temp = split(/#/, "abc#def#ghi#jkl") ;
> > >
> > > doesn't seem to work.
> > >
> > > am i doing anything wrong here ?
> > 
> > Try this:
> > 
> > @temp = split('\#', "abc#def#ghi#jkl") ;
> > foreach (@temp){
> >  print "\n", $_;
> > }
> 
> The first argument to split is converted to a regular expression and the
> '#' character is not special in a regular expression so split/#/ and
> split'\#' do exactly the same thing.

Well, actually they don't, since the 'bare' # will be interpreted as
starting a comment, while the one in quotes won't...  ;^)

The op's assignment was assigning 'split(/' to @temp...

j

> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment
-- 
"Not all those who wander are lost."  - JRR Tolkien


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Split question

2003-12-14 Thread R. Joseph Newton
Joel Newkirk wrote:

> > The first argument to split is converted to a regular expression and the
> > '#' character is not special in a regular expression so split/#/ and
> > split'\#' do exactly the same thing.
>
> Well, actually they don't, since the 'bare' # will be interpreted as
> starting a comment, while the one in quotes won't...  ;^)
>
> The op's assignment was assigning 'split(/' to @temp...
>

Hi Joel,

Did you test.  The only problem I see with John's code is that it addumes that
the print statement will print a newline, which it doesn't [at least on my
installation of V5.8].  On the main point, he is right.

Greetings! E:\d_drive\perlStuff\giffy>perl -w
@temp = split(/#/, "abc#def#ghi#jkl");
print "$_\n" for @temp;
^Z
abc
def
ghi
jkl

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Split question

2003-12-14 Thread John W. Krahn
Joel Newkirk wrote:
> 
> On Sun, 2003-12-14 at 14:52, John W. Krahn wrote:
> > Josimar Nunes De Oliveira wrote:
> > >
> > > From: "Perl" <[EMAIL PROTECTED]>
> > > >
> > > >   @temp = split(/#/, "abc#def#ghi#jkl") ;
> > >
> > > @temp = split('\#', "abc#def#ghi#jkl") ;
> >
> > The first argument to split is converted to a regular expression and the
> > '#' character is not special in a regular expression so split/#/ and
> > split'\#' do exactly the same thing.
> 
> Well, actually they don't, since the 'bare' # will be interpreted as
> starting a comment, while the one in quotes won't...  ;^)

In both cases the # is quoted.  Read the document perlop.pod from "Quote
and Quote-like Operators" to the end for enlightenment.

perldoc perlop



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: could use an audit

2003-12-14 Thread Kenton Brede
On Fri, Dec 12, 2003 at 06:20:45PM -0600, Kenton Brede wrote:
> I've cobbled some code together that will allow me to parse a file


Thanks all for your help.  I've learned a ton:)
Kent

-- 
"I am always doing that which I can not do, 
   in order that I may learn how to do it." --Pablo Picasso


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Split question

2003-12-14 Thread James Edward Gray II
On Dec 14, 2003, at 6:42 PM, R. Joseph Newton wrote:

The only problem I see with John's code is that it addumes that
the print statement will print a newline, which it doesn't [at least 
on my
installation of V5.8].
Na, John's smarter than you give him credit for here.  Here was the 
code:

On Dec 13, 2003, at 11:20 PM, John W. Krahn wrote:

$ perl -le'
@temp = split(/#/, "abc#def#ghi#jkl");
print for @temp;
'
Lookup that -l command-line switch, which is mighty handy and probably 
underused...  ;)

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



hash sorting

2003-12-14 Thread B. Rothstein
I have a hash where each key is a first name linked to a last name, any
suggestions on how to loop through the hash to sort the list by the last
names? 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


Re: hash sorting

2003-12-14 Thread Randy W. Sims
On 12/15/2003 3:17 AM, B. Rothstein wrote:
I have a hash where each key is a first name linked to a last name, any
suggestions on how to loop through the hash to sort the list by the last
names? 

Check the Perl FAQ.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: hash sorting

2003-12-14 Thread Owen
On Mon, 15 Dec 2003 00:17:17 -0800
"B. Rothstein" <[EMAIL PROTECTED]> wrote:

> I have a hash where each key is a first name linked to a last name, any
> suggestions on how to loop through the hash to sort the list by the last
> names? 


Something like this perhaps?

#!/usr/bin/perl -w

use strict;

my %h = (
 Jo => "Blow",
 Al => "Smith",
 Ok => "Corale"
 );

foreach my  $person(sort {$h{$a} cmp $h{$b} }
keys %h)

{
print "$person is $h{$person}\n";
}

__END__
Jo is Blow
Ok is Corale
Al is Smith


Straight from the Perl Cookbook

-- 
Owen


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]