Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

afjkpajfapjf

Name: Anonymous 2011-03-06 18:44

Hello gentlemen,

How do I assign by reference in perl?

Let's say I just opened a file which had the structure HEADER BODY FOOTER:

open(FINPUT, "< $ARGV[0]") or die "can't open $ARGV[0]\n";

$data = <FINPUT>;

$file =~ /^header_marker(.*?)\ body_marker(.*?)\ footer_marker(.*?)$/;

print "header: $1\n";
print "footer: $3\n";

$body = $2;


After reading the header and footer I'd like to put the body into a seperate variable for further processing. I can't keep it in $2 as I plan to do more regexps later that will fill it.

But am I right in saying that $body = $2 will create a copy in $body? If so, how do I just assign a reference instead so both $body and $2 just point to the same block of data?

Name: Anonymous 2011-03-06 18:45

$fuck

Name: Anonymous 2011-03-07 4:23

Yes, when you write $body = $2, then $body is assigned the value of whatever the fuck $2 is. I'm not sure what you mean by the second question. They already have the exact same value...

Don't change these.
Name: Email:
Entire Thread Thread List