in reply to Re^3: Assistance fixing a "format" call
in thread Assistance fixing a "format" call

Marshall, thanks very much for the welcome, and the nice informative responses - very much appreciated!!

One question for you (I'm in the process of writing up another question, and am working on the example code, and need to do some tweaking in order to make it runnable in it's current reduced format) regarding the __DATA__ tag. Is there a way to emulate a second data source? I notice you said if there's a single file that you use... if it's more than one, can you use, perhaps __DATA2__ to emulate the second file??

  • Comment on Re^4: Assistance fixing a "format" call

Replies are listed 'Best First'.
Re^5: Assistance fixing a "format" call
by Marshall (Canon) on Apr 04, 2012 at 03:47 UTC
    There can be only one __DATA__ segment, however there is another way! Use a heredoc and assign that to a variable, then you can open that variable for reading just like a file! WoW! This is way cool. Note the reference (\$data2) in the open statement.
    #!/usr/bin/perl -w use strict; my $data2 =<<END; This is an example of another way to do this than the DATA segment END open DATA2, '<', \$data2 or die $!; while (<DATA2>) { print; } __END__ Prints: This is an example of another way to do this than the DATA segment
    Note that it is also possible to open a variable for writing! This is handy sometimes to avoid making a temporary file that you have to delete.