Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: simply appending to a scalar...

by ikegami (Patriarch)
on Jun 28, 2006 at 05:10 UTC ( [id://557928]=note: print w/replies, xml ) Need Help??


in reply to Re: simply appending to a scalar...
in thread simply appending to a scalar...

Examples of mentioned solutions:

  • $data = $data . $more;
  • $data .= $more;
  • substr($data, length($data), 0, $more);
  • substr($data, length($data)) = $more;
  • $data = join('', $data, $more);
  • $data =~ s/\z/$more/;
  • $data =~ "$data$more";
  • { open(my $fh, '>+', \$data); print $fh $more; } (Requires 5.8)

Other useful solutions:

  • $data = sprintf('%s%s', $data, $more);
  • $data = pack('a*a*', $data, $more);
  • $data = pack('(a*)*', $data, $more); (Requires 5.8)
  • $data = do { local $"; my @array = ($data, $more); "@array" };

Other text formatting functions:

  • format formats text sent to a file handle.
  • formline is the guts of format.

And that's only using tools meant for text manipulation and/or formatting. You could do weird stuff like:

  • $data = reverse scalar reverse $data, $more;
  • $data = do { local $;; my %hash; $hash{$data, $more}++; (keys(%hash))[0] };

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-28 21:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found