Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Don't ask to ask, just ask
 
PerlMonks  

Re^2: write and read the same file not display the output

by ulaksh (Acolyte)
on Sep 05, 2012 at 00:53 UTC ( #991717=note: print w/ replies, xml ) Need Help??


in reply to Re: write and read the same file not display the output
in thread write and read the same file not display the output

thanks for the help

Now I am trying in different way, please correct if I am wrong

while ( <$fi> ) { #print "$_"; my $a = $1 if /(^$name$)/; print $a; } close $fi;

But when I run the file output show nothing, and it shows me some message, I am not getting where is the issue please see the below output

perl readwritefile.pl Use of uninitialized value $a in print at readwritefile.pl line 15, <$ +fi> line 1. Use of uninitialized value $a in print at readwritefile.pl line 15, <$ +fi> line 2. Use of uninitialized value $a in print at readwritefile.pl line 15, <$ +fi> line 3.


Comment on Re^2: write and read the same file not display the output
Select or Download Code
Re^3: write and read the same file not display the output
by Rudolf (Monk) on Sep 05, 2012 at 01:53 UTC

    Hello ulaksh, Im guessing youve commented out your print "$_"; on purpose there. Anyway your getting yelled at because when the regex doesnt make a match, $a is not getting defined at all, so it is still undefined. You then try to use it on the next line print $a; You cant print $a because it has no value. It is undefined at the moment. This is also the reason your not getting anything printed to screen. maybe you can try this instead? :

    print $1 if /^($name)$/;

      Good eye, Rudolf! Did you mean:

      print $1 if /^($name)$/;

        Hey thanks for the nice reply, but I was not aware of a difference in the regex with the parentheses (though I updated my post): It would be good if you can point it out for me, always up for learning more Perl ! :-)

        print $1 if /^$name$/; #or print $1 if /^($name)$/;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991717]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2014-04-19 16:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (483 votes), past polls