legend has asked for the wisdom of the Perl Monks concerning the following question:

I have a function that takes input as follows:
my $query = dbQuery( <<EOQ ); SUBJECT="ELECTRONICS" AUTHOR="JOHN" EOQ
If I want to put this into another file, how would I let the function take this value? I mean, suppose that I place
SUBJECT="ELECTRONICS" AUTHOR="JOHN"
into a different file,say filter.txt and supply it from command line as perl <filename> filter.txt, how would I make the program work? Can someone help me out please?

Replies are listed 'Best First'.
Re: Achieving something similar to <<EOQ
by grinder (Bishop) on Mar 08, 2008 at 22:01 UTC

    Uh... by reading the file?

    my $query = dbQuery( do{local $/ = undef; open my $in, shift and <$in>} );

    You might want to toss in a bit of error-checking in case the file doesn't exists, or the program lacks the privileges to read it.

    • another intruder with the mooring in the heart of the Perl

Re: Achieving something similar to <<EOQ
by chromatic (Archbishop) on Mar 08, 2008 at 22:01 UTC

    You need to read that text into a variable and pass that variable to the function. I suggest reading the documentation for open, readline, and possibly chomp.

Re: Achieving something similar to <<EOQ
by duelafn (Parson) on Mar 09, 2008 at 02:54 UTC

    Most friendly syntax would define a sub

    sub cat { my ($mode, $f) = ("<", @_); open my $F, $mode, $f or die "Can't open $f for reading: $!"; local $/ = undef; return scalar <$F>; }

    See also File::Slurp

    Good Day,
        Dean