The problem is that a list (ie @foo) inside another list (ie @_)
gets expanded -- the list items are all there, but no longer enclosed
in a distinct list. If
@foo = (a, b, c), then your subroutine
sees
$_[1] as 'a',
$_[2] as 'b', etc.
To fix this, you could just print all of the remaining items in @_ inside
writeFile, or else you could preserve @file's identity as a distinct list by passing it
in as a reference:
&writeFile("file.txt", \@file);
Now, as far as writeFile is concerned, $_[1] contains a reference that points to all
of @file, not just the first line. To use this correctly, you must also modify the print statement
slightly:
print FILE @$_[1];
'@$_[1]' indicates that the program should
access the array or '@' that '$_[1]' is a reference to.
It can also be written as @{$_[1]}, if that helps.
See perldoc
perlreftut
for a references tutorial, not to mention the various O'Reilly
books.
-- Frag.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.