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:
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
But am I right in saying that
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?