PS: Expression problem
- From: "Mr P" <MisterPerl@xxxxxxxxx>
- Date: 28 Nov 2006 07:51:26 -0800
.
The $details array is read in from a text file and this works fine.
What I want to do is search the $details text for certain key words,
then take the text right after. The first if statement
.
I just noticed this comment about reading from a file, although you
don't show your code for that. I will share this approach which works
well for me and my team, and is nice and tidy. I call it the guerilla
approach- get into the file, snag it, get out!
die "This file will not open here is why: \n$!\n" unless open T,
'mytextfile.txt';
my @details = <T>;
close T;
for ( @details )
{
.
.
.
}
If you REALLY want a lot of info about the file and failure, you can
use some cool Perl file tests:
# lots of details...
die "aint no such file as $myFile\n" unless -e $myFile;
die "$myFile is a directory not a file!\n" unless -d $myFile;
die "the file $myFile is there but I cannot read it\n" unless -r
$myFile;
die "the file $myFile is there but I cannot open it for reading
(locked maybe?)\n$!\n"
unless open T, $myFile;
my @details = <T>;
close T;
die "I opened and read $myFile but there wasnt nothing in it, wanna
try again ace?\n"
unless @details;
Welcome to the wonderful world of Perl, you make a wise choice
grasshopper!
PS: do you own due-diligence on my and other comments and suggestions
and choose what works best for you. Larry often states that in Perl
there are MANY ways to do things. Often you'll see a lot of approaches
to questions here in CLPM - study them and choose the best for you.
Although I've read Llama, Camel, even big black cat, I would still say
that I've learned 75% of my Perl right here in this group. Often I'll
slap my forehead after seeing a reply and think "DUH how did I MISS
that!"..
.
- References:
- Expression problem
- From: K.J. 44
- Expression problem
- Prev by Date: Re: Expression problem
- Next by Date: Re: literal substitution
- Previous by thread: Re: Expression problem
- Next by thread: Interactive programs & Teeing
- Index(es):
Relevant Pages
|
|