Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by Rudolf (Pilgrim)
on Sep 05, 2012 at 03:08 UTC ( #991729=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^6: write and read the same file not display the output
by Kenosis (Priest) on Sep 05, 2012 at 04:53 UTC

    $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

      ahh I see, thats valuable information I lost along the way haha thank you for taking the time to explain. Enjoy your week! -Rudolf

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991729]
help
Chatterbox?
[Lady_Aleena]: Or what Discipulus said.
[shmem]: Lady_Aleena: geany supports ctags.
[Discipulus]: a good compromise can be my ($need, $opts_ref) = @_ a scalar and an hash reference
[Discipulus]: see you monks!
[Lady_Aleena]: shmem, let me get this sub rewritten, then I will look into how to use ctags in geany. Deal? 8)
[shmem]: Discipulus: yeah, that might eventually prepare the path for OO ;-)
[Lady_Aleena]: See you, Discipulus.
[shmem]: Lady_Aleena: that's up to you. I only wanted to show you a path that might be more comforting than command line grep ;-)
[Lady_Aleena]: shmem, I don't think any of my modules could be converted to OO. They are too procedural.
[Lady_Aleena]: Now I will see if my perl-fu is as bad as I think it is.

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2017-04-27 12:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (506 votes). Check out past polls.