Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by Rudolf (Monk)
on Sep 05, 2012 at 01:53 UTC ( #991720=note: print w/ replies, xml ) Need Help??


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

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)$/;


Comment on Re^3: write and read the same file not display the output
Download Code
Re^4: write and read the same file not display the output
by Kenosis (Priest) on Sep 05, 2012 at 02:07 UTC

    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)$/;

        $1 is initialized via regex captures which use parentheses. For example, in the following:

        my $string = 'Frank'; my $name = 'Frank'; print $1 if $string =~ /^$name$/; print $1 if $string =~ /^($name)$/;

        The first print statement produces:

        Use of uninitialized value $1 in...

        Whereas, the second print shows the value in $1:

        Frank

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2014-08-29 23:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (289 votes), past polls