If I intuit your intent properly, there are two changes you need to make:
- =foreach needs to be foreach. You have made a syntax error that makes the interpreter think you are entering a documentation mode (see perlpod), thus no useful error message.
- Rather than <*>, which operates as a glob, you mean <>, which reads off STDIN.
So a functional version of your code might be
@files = <>;
chomp @files; # Since there are trailing newlines
foreach $file (@files) {
if (-f $file) {
print "This is a file: " . $file."\n";
}
if (-d $file) {
print "\n\nThis is a directory: " . $file."\n";
}
}
or, if I wrote it,
use strict;
use warnings;
my @files = <>;
chomp @files;
foreach my $file (@files) {
if (-f $file) {
print "This is a file: $file\n";
}
if (-d $file) {
print "\n\nThis is a directory: $file\n";
}
}
What materials are you using to learn Perl? There are a number of great resources, including some free ones. For thorough coverage of available learning resources, see
http://learn.perl.org.
Update: Corrected omitted chomp.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
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.