Re: matching array elements from hash ?

2012-08-20 Thread jet speed
On Sun, Aug 19, 2012 at 10:48 PM, timothy adigun <2teezp...@gmail.com>wrote: > Hi, > > Please, Check my comments below. > > On 8/19/12, jet speed wrote: > > Hi All, > > > > Is there a way to find matching array elements from hash. > > > > ex: > > > > @names = ( abc. def. ghi, jky; ); > > The a

Re: matching array elements from hash ?

2012-08-20 Thread jet speed
Thanks John, worked as a treat. Appreciate it. On Sun, Aug 19, 2012 at 11:18 PM, John W. Krahn wrote: > jet speed wrote: > >> Hi All, >> > > Hello, > > > Is there a way to find matching array elements from hash. >> >> ex: >> >> @names = ( abc. def. ghi, jky; ); >> >> %stud = ( >> " abc" =>"

Re: matching array elements from hash ?

2012-08-20 Thread Andy Bach
On Sun, Aug 19, 2012 at 4:48 PM, timothy adigun <2teezp...@gmail.com> wrote: > foreach my $match_value ( sort keys %stud ) { > print $match_value, "=", $stud{$match_value}, > $/ if $match_value ~~ @names; > } "smart match" is a Perl 6 (though it probably back ported to a Perl 5 modul

Re: matching array elements from hash ?

2012-08-20 Thread Jim Gibson
The "smart match" operator (~~) was introduced in Perl 5.10. If you are using a Perl earlier than that, you will get a syntax error. See perldoc perl5100delta perldoc perlsyn and search for "Smart". -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: b

Re: matching array elements from hash ?

2012-08-20 Thread timothy adigun
Hi, > Hi Tim, > > Thanks, i tried to run the code, but get the error as below. Any thing i am > missing line 17. What version of Perl are you using? For smart matching to work you must have Perl 5.10.1 Up (the 5.10.0 version behaved differently). > syntax error at ./match2.pl line 17, near "$m

Re: matching array elements from hash ?

2012-08-20 Thread timothy adigun
Hi Andy, On 8/20/12, Andy Bach wrote: > On Sun, Aug 19, 2012 at 4:48 PM, timothy adigun <2teezp...@gmail.com> > wrote: >> foreach my $match_value ( sort keys %stud ) { >> print $match_value, "=", $stud{$match_value}, >> $/ if $match_value ~~ @names; >> } > > "smart match" is a Perl

re-reading from already read file handle

2012-08-20 Thread Rajeev Prasad
I opened a file to read from line by line. open(FH,"<","$myfile") or die "could not open $myfile: $!"; while () { ...do something } later on in program, try to re-read the file (walk thru the file again): while () { ...do something } and realized that it is as if the control within file is a

Re: re-reading from already read file handle

2012-08-20 Thread Andy Bach
On Mon, Aug 20, 2012 at 2:00 PM, Rajeev Prasad wrote: > is this default behaviour? how to work around this? file is big and I do not > want to keep in memory as array. so is my only option is to close and open > the file again? Yes, that's the default. "seek" lets you reset things though perldo

Re: re-reading from already read file handle

2012-08-20 Thread Shawn H Corey
On Mon, 20 Aug 2012 12:00:55 -0700 (PDT) Rajeev Prasad wrote: > open(FH,"<","$myfile") or die "could not open $myfile: $!"; # You should used a my variable for the file handle open(my $fh,"<","$myfile") or die "could not open $myfile: $!"; > while () # with the my variable file handle while (<

awk to Perl

2012-08-20 Thread Chris Stinemetz
Hello List, I'm tyring to covert an AWK script to Perl. Is there a better alternative then a2p? http://perldoc.perl.org/a2p.html Thanks in advance, Chris

Re: re-reading from already read file handle

2012-08-20 Thread Rajeev Prasad
thank you. seek did the job. by the way can this be made any better? just want to find out in how many records string was found:             my $count=0;             seek $tmp_FH,0,0;             while (<$tmp_FH>)             {                 my $line=$_;chomp($line);                 if ($line=

Re: awk to Perl

2012-08-20 Thread Shawn H Corey
On Mon, 20 Aug 2012 15:35:23 -0500 Chris Stinemetz wrote: > I'm tyring to covert an AWK script to Perl. Is there a better > alternative then a2p? Better is a relative term. Do you mean faster or more convenient? No. Do you mean higher quality? Yes, hire a professional Perl programmer. ;) -- J

Re: re-reading from already read file handle

2012-08-20 Thread Shawn H Corey
On Mon, 20 Aug 2012 13:39:16 -0700 (PDT) Rajeev Prasad wrote: >             my $count=0; >             seek $tmp_FH,0,0; >             while (<$tmp_FH>) >             { >                 my $line=$_;chomp($line); # Please put each statement on its own line >                 if ($line=~m/\"$str\

Re: re-reading from already read file handle

2012-08-20 Thread Jim Gibson
On Aug 20, 2012, at 1:39 PM, Rajeev Prasad wrote: > thank you. seek did the job. > > by the way can this be made any better? > > just want to find out in how many records string was found: > > my $count=0; > seek $tmp_FH,0,0; > while (<$tmp_FH>) >

Re: awk to Perl

2012-08-20 Thread Andy Bach
On Aug 20, 2012, at 3:35 PM, Chris Stinemetz wrote: > I'm tyring to covert an AWK script to Perl. Is there a better alternative > then a2p? How big's the script? I remember using a2p long ago (I'd learned awk and sed first even) and it wasn't great; bad even depending on the complexity. If

Re: re-reading from already read file handle

2012-08-20 Thread Rajeev Prasad
Thx. I did some timestamp prints from within script, this piece is taking too long: almost 5 minutes to complete...!!! fyi, the strArr array contains about 1500 string elements. (this loop runs that many times) the file tmp_FH_SR  is 27Mb and 300,000 lines of data. the file tmp_FH_RL is 13 Mb

Re: re-reading from already read file handle

2012-08-20 Thread Jim Gibson
On Aug 20, 2012, at 3:32 PM, Rajeev Prasad wrote: > Thx. I did some timestamp prints from within script, this piece is taking too > long: almost 5 minutes to complete...!!! > > fyi, the strArr array contains about 1500 string elements. (this loop runs > that many times) > the file tmp_FH_SR i

Re: re-reading from already read file handle

2012-08-20 Thread Rob Dixon
Rajeev Prasad wrote: >I opened a file to read from line by line. > > >open(FH,"<","$myfile") or die "could not open $myfile: $!"; >while () >{ >...do something > >} > >later on in program, try to re-read the file (walk thru the file >again): >while () >{ >...do something > >} > >and realized tha

Re: re-reading from already read file handle

2012-08-20 Thread Rajeev Prasad
Rob, yes you are right. I apologize if that is not liked. I will not do so in future. I will atleast wait a couple of hours, before i go to any other forum. your help is valuable to me. ty. Rajeev From: Rob Dixon To: Rajeev Prasad ; perl list Sent: Monday,

Re: re-reading from already read file handle

2012-08-20 Thread John SJ Anderson
On Monday, August 20, 2012 at 4:15 PM, Rob Dixon wrote: > > This question is double-posted on Stack Overflow > So what? I don't see anything in the list FAQ about cross-posting questions to other resources, just about cross-posting across the different beginner mailing lists. john. -- John

Re: re-reading from already read file handle

2012-08-20 Thread Bill Stephenson
On Aug 20, 2012, at 7:24 PM, John SJ Anderson wrote: > On Monday, August 20, 2012 at 4:15 PM, Rob Dixon wrote: >> >> This question is double-posted on Stack Overflow >> > So what? I don't see anything in the list FAQ about cross-posting questions > to other resources, just about cross-posting a