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

Re: my $x = <expr>; vs my $x; $x = <expr>;

by Abigail-II (Bishop)
on Jun 05, 2004 at 22:04 UTC ( [id://361692]=note: print w/replies, xml ) Need Help??


in reply to my $x = <expr>; vs my $x; $x = <expr>;

Well, if there's a source filter, or if 'some expression' invokes some XS code that walks the parse tree, there might be a difference. But normally, there won't be any semantic difference. There will be a small speed difference though, since the second expression will store an undefined value in $x before assigning 'some expression':
#!/usr/bin/perl use strict; use warnings; no warnings qw /syntax/; use Benchmark qw /cmpthese/; cmpthese -1 => { single => 'my $x = "foo"', double => 'my $x; $x = "foo"', }; __END__ Rate double single double 2710223/s -- -14% single 3143931/s 16% --

Abigail

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-04-19 15:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found