Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Variable assignment confusion

by fruiture (Curate)
on Dec 15, 2003 at 17:48 UTC ( #314862=note: print w/replies, xml ) Need Help??


in reply to Variable assignment confusion

Well, you're assigning either the result of a match or, if the match is without success, the retid + "_001". It's not true that this always assigns 1, it only assigns 1 when the match is successfull, because a simple m// returns a boolean (undef or 1) and || will return it's left operand's result if it's true.

What you want is, as you said:

# parens not neccessary here
my $new_retid = 
# if the retid has the suffix
    $retid =~ /_\d{3}$/ ?
# then leave it as is
    $retid :
# otherwise add _001 suffix
   $retid.'_001'

See perlop for "?:" and the behaviour of m//. HTH

--
http://fruiture.de

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://314862]
help
Chatterbox?
[GotToBTru]: okay, fess up, who installed CB::Typo?
[Discipulus]: at 7th floor seagulls eat mice
[Discipulus]: just in Eataly: brain surgery while playing clarinet..
[erix]: installing perfect pitch?

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (13)
As of 2017-11-17 20:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (272 votes). Check out past polls.

    Notices?