Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Re: Re: Memory Use/Garbage Collection: Java vs Perl

by John M. Dlugosz (Monsignor)
on Sep 03, 2002 at 14:53 UTC ( #194784=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Re: Memory Use/Garbage Collection: Java vs Perl
in thread Memory Use/Garbage Collection: Java vs Perl

The Perl version needs to concatenate strings, too!

perl -MO=Deparse,-q -e"print qq(I am $x\n)"
produces
print 'I am ' . $x . "\n";
not print ('I am ' , $x , "\n" ) .

That is, Perl concatenates the literals and variables together into one string, then calls print with the result.

—John


Comment on Re: Re: Re: Re: Memory Use/Garbage Collection: Java vs Perl
Select or Download Code
Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Memory Use/Garbage Collection: Java vs Perl
by BrowserUk (Pope) on Sep 03, 2002 at 15:09 UTC

    That's interesting, thanks. Am I correct in my (I'm not sure if it's a memory of something I read somewhere, or an assumption I have formed) that Perl will fold string constants?

    From my (brief and un-expert) look at the byte code produced by javac, it seems to be pushing a new copy of the two constants onto the stack (they could be pointers to a single copy, I can't make up my mind) prior to the call to StringBuffer, at each invokation?

    Whereas I assume that Perl would push a reference to a single copy of each.

    Thinking about that, javac is probably pushing a pointer too.



    Well It's better than the Abottoire, but Yorkshire!
      Am I correct in my (I'm not sure if it's a memory of something I read somewhere, or an assumption I have formed) that Perl will fold string constants?

      Apparently it does not.

      perl -MO=Deparse,-q -e"print qq(I am $x\n) . 'and fold this?'"
      it taken as
      print(('I am ' . $x . "\n") . 'and fold this?');
      not print('I am ' . $x . "\nand fold this?").

      —John

        True, but

        perl -MO=Deparse,-q -e "print 'Hello, ' . 'World'"

        Is parsed as

        print 'Hello, World'; -e syntax OK

        Apparently, the example you gave was more complex than the parser wanted to deal with.

        Update Added -q, as John pointed out below...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2015-07-07 23:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls