Question : Perl file parsing help

Hello Perl people..

I have a txt file which I need to read the first 4 lines separately into variables of some sort then all the remainder lines can be considered one block or variable.

so my text file would be like whats in the embedded code below. Imagine its called 'text.txt'

then a Perl sub routine parses 'text'txt' into 5 variables which would be stored as:

$template="magazine";
$ID=2;
$title="My Title";
$text="Some text which can be multiple lines long
and could contain
any characters!@#$%^&*(*&^%$#
";

so I would want to have a line like:
my ($template, $ID, $title, $text)=custom_file_parse("text.txt");

some help would be much appreciated to do this,

Cheers,

Tim
1:
2:
3:
4:
5:
6:
magazine
2
My Title
Some text which can be multiple lines long
and could contain 
any characters!@#$%^&*(*&^%$#

Answer : Perl file parsing help

1:
2:
3:
4:
5:
6:
7:
8:
sub custom_file_parse{
    my $file = shift;
    open(INFILE, "<$file") or die $!;
    my ($template, $ID, $title, @arr) = <INFILE>;
    close(INFILE) or die $!;
    my $text = join("", @arr);
    return ($template, $ID, $title, $text);
}
Random Solutions  
 
programming4us programming4us