Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

A memory problem?

by DDH (Initiate)
on Apr 13, 2005 at 14:03 UTC ( [id://447385]=perlquestion: print w/replies, xml ) Need Help??

DDH has asked for the wisdom of the Perl Monks concerning the following question:

my $mystring = "test"; my $temp2 = $mystring; if ($temp2 =~ m/^[a-zA-Z]+$/) { $naam = $1; } else { die "Wrong input"; } print "Het woord is $1"; my $uur = 24; my $temp1 = $uur; if($temp1 < 25 && $temp1 =~ /\d\d/) { $uur = $1; } else { die "Geen correcte tijdsduur. Niet meer dan 24 uren ingeven!!"; } print "$uur";

I have two if statements the second if i check if the number is less then 24 when this is true then $uur = $1. And i Think that $1 is the first variable that is in the memory or something like that?

The first if is exactly the same but there i check if the string consists of the caracters a-zA-Z if this is true then $naam = $1 but when i print the variable $naam it has nog value. Can someone explain this?

20050413 Janitored by Corion: Added formatting

Replies are listed 'Best First'.
Re: A memory problem?
by prasadbabu (Prior) on Apr 13, 2005 at 14:10 UTC

    You missed paranthesis.

    Use if ($temp2 =~ m/^([a-zA-Z]+)$/)

    Update:

    In your previous post they have(PMs) explained about using paranthesis to store the values in a variable.

    Prasad

Re: A memory problem?
by RazorbladeBidet (Friar) on Apr 13, 2005 at 14:13 UTC
    I really suggest you read things like perlretut before asking more questions of this type. They're all fairly simple and can be answered quickly. Not trying to be unfriendly, I just noticed this and your other question were part of the basics.
    --------------
    "But what of all those sweet words you spoke in private?"
    "Oh that's just what we call pillow talk, baby, that's all."
Re: A memory problem?
by tlm (Prior) on Apr 13, 2005 at 14:12 UTC

    To capture a match in $1, you need to stick it between ()s; your regexp should be:

    /^([a-zA-Z]+)$/

    the lowliest monk

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://447385]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-29 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found