Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Uninitialized Value $regex

by Athanasius (Archbishop)
on Jun 05, 2015 at 01:56 UTC ( [id://1129149]=note: print w/replies, xml ) Need Help??


in reply to Uninitialized Value $regex

Hello ra93013,

Just a side note — this:

$args{dir} = $DEFAULT_DIRECTORY unless defined( $args{dir} ); $args{log} = $DEFAULT_LOG_FILE unless defined( $args{log} ); $args{pattern} = $DEFAULT_PATTERN unless defined( $args{pattern} ); $args{sendto} = $DEFAULT_SEND_TO unless defined( $args{sendto} ); $args{help} = 0 unless defined( $args{help} );

can be written more succinctly as:

$args{dir} //= $DEFAULT_DIRECTORY; $args{log} //= $DEFAULT_LOG_FILE; $args{pattern} //= $DEFAULT_PATTERN; $args{sendto} //= $DEFAULT_SEND_TO; $args{help} //= 0;

See perlop#Logical-Defined-Or.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Uninitialized Value $regex
by afoken (Chancellor) on Jun 05, 2015 at 10:15 UTC
    can be written more succinctly ... See perlop#Logical-Defined-Or.

    Yes, but not in perl versions older than 5.10 (released Dec 2007) / 5.9 (released Jul 2007), see perl5100delta /perl590delta. Older perl versions will likely see this as a syntax error. Unfortunately, this little detail is not documented in perlop. For someone new to Perl, perlop must read like defined-or was always present in Perl.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      ... not in perl versions older than 5.10 ...

      In any version of Perl, the command-line  perldoc perlop (and other docs) can be a very welcome local feature sanity check. It's saved me wasted motion more than once.

      The on-line perlop (and on-line documentation in general) is tied to the most recent Perl version and is perhaps a bit overenthusiastic in presenting new features, but even this can be dialed back to previous versions (back to 5.8, IIRC).


      Give a man a fish:  <%-(-(-(-<

        One of the reasons why Syntax::Construct exists.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found