[17119] in Perl-Users-Digest
Perl-Users Digest, Issue: 4531 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 5 18:05:45 2000
Date: Thu, 5 Oct 2000 15:05:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <970783514-v9-i4531@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 5 Oct 2000 Volume: 9 Number: 4531
Today's topics:
[Q] Make File Handle into a reference as returned from <blavender@spk.usace.army.mil>
Re: a 14 day counter <lr@hpl.hp.com>
Re: automatic email attachments <dave@marballs.co.uk>
beginner question <vrdoljak@uclink.berkeley.edu>
Re: beginner question (John J. Trammell)
Re: beginner question <yanick@babyl.sympatico.ca>
Re: beginner question <elijah@workspot.net>
Re: beginner question (Chris Fedde)
Re: beginner question (Clay Irving)
Re: beginner question <lr@hpl.hp.com>
Re: beginner question <tony_curtis32@yahoo.com>
Can Perl extension on UNIX be C++ ? <kolonay@micro.ti.com>
Can't lock error <jpsmith@mediom.qc.ca>
Changing STDOUT buck_naked@NOiname.SPAMcom
Changing STDOUT <bart.lateur@skynet.be>
Re: Changing STDOUT <yanick@babyl.sympatico.ca>
counter problem HELP amy_v@my-deja.com
Re: date conversion <lr@hpl.hp.com>
Re: Does anyone have a jed mode for perl <jeff@vpservices.com>
Re: Forking, Exiting, and Timing out within an Eval <bkennedy@hmsonline.com>
Help processing files in a directory <michael.segulja@sgi-lsi.com>
Re: Help processing files in a directory (Gary E. Ansok)
Re: How? Read a file from another server? (Clay Irving)
Re: HTML::Parser question (David Wall)
MIME::Entity question jdaves@gilanet.com
Re: new (Willow)
Re: new <gp@no.thanks>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 05 Oct 2000 18:38:51 GMT
From: Brian Lavender <blavender@spk.usace.army.mil>
Subject: [Q] Make File Handle into a reference as returned from CGI.pm
Message-Id: <8rihrq$hqe$1@nnrp1.deja.com>
I am using the CGI.pm to upload a file from a web page. It returns a
file handle. I am also using Text::CSV_XS perl module to parse the
uploaded file . The class method new to instatiate the
Text::CSV_XS object requires that you pass it a file handle reference. I
can use IO::File to create a file handle reference to a file, and pass
that to the Text::CSV_XS perl module, but I can't quite figure out how
to turn the file handle returned by the CGI perl module into a file
handle reference to pass to the Text::CSV_XS perl module new class
method. Here's code that works, and below that, is code that I am trying
to make work. What changes do I need to make to make the second case
work?
First Case: (Works)
#!/usr/local/bin/perl -Tw
use Text::CSV_XS;
use IO::File;
use strict;
my $fh;
$fh = new IO::File;
$fh->open("< ./39da1f686d2f.csv");
$csv = Text::CSV_XS->new($fh);
my @table = ();
my $columns;
while ( ($columns = $csv->getline($fh) ) && ( @$columns ) ) {
push @table, $columns;
print join "|", @$columns , "\n";
}
Second Case (Can't get this to work!):
#!/usr/local/bin/perl -Tw
use Text::CSV_XS;
use IO::File;
use CGI qw/:standard/;
use strict;
my $fh; # File handle reference
print header,
start_html('file upload'),
h1('file upload');
if (param) {
my $file = param('upload');
$fh = new IO::File;
$fh->open($file) || die "Unable to create file handle object $!\n";
print "<PRE>\n";
csv_process($fh);
print "</PRE>\n";
} else {
print_form();
}
print end_html,"\n";
sub print_form {
print start_multipart_form(),
filefield(-name=>'upload',-size=>60),br,
submit(-label=>'Upload File'),
end_form;
}
sub csv_process {
my $fh = $_[0];
my $csv;
my @table;
my $i;
$csv = Text::CSV_XS->new($fh);
@table = ();
$i = 0;
my $columns;
while ( ($columns = $csv->getline($fh) ) && ( @$columns ) ) {
# Read a line from file $io, parse it
# and return an array ref of fields
push @table, $columns;
print join "|", @$columns , "\n";
}
}
--
Brian E. Lavender
US Army Corps of Engineers -- Programmer / Systems Analyst
Sacramento, CA (916) 557-6623
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 5 Oct 2000 11:12:08 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: a 14 day counter
Message-Id: <MPG.14466451cecf943898ae0d@nntp.hpl.hp.com>
In article <6lkots0sc6oqlslt20msgvg9vlts29cshf@4ax.com> on Thu, 05 Oct
2000 10:06:40 GMT, Bart Lateur <bart.lateur@skynet.be> says...
> Drew Simonis wrote:
>
> >Use Julian days and your life becomes simple.
>
> What is this "Julian Days" thing that keeps popping up? Why is it better
> than, say, days since Jan 1 1970?
Of course it isn't better.
'Julian Day' is often used misleadingly to refer to the $yday output of
localtime() -- days elapsed since January 1. This misnomer is
perpetuated by the '%j' format specifier of strftime().
In fact, Julian Date and Modified Julian Date refer to days since
particular epochs, and the Unix Epoch is as valid a reference point as
either of them for dates in the 'computer era'. The others are more
useful for astronomical or historical reckonings.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 5 Oct 2000 19:40:11 +0100
From: "Dave" <dave@marballs.co.uk>
Subject: Re: automatic email attachments
Message-Id: <8rimd5$cmc$1@news8.svr.pol.co.uk>
Thanks everyone for the help. Unfortunately, my web server provider is very
bad on providing answers probably because they are cheap.
They do not seem to know much about CGI and just say I should use PHP.
Therefore I thought I would seek guidance from you guys for some help, which
you have been. I am more clued up about modules etc. so thanks to all
"Villy Kruse" <vek@pharmnl.ohout.pharmapartners.nl> wrote in message
news:slrn8tghbi.nek.vek@pharmnl.ohout.pharmapartners.nl...
> On Sun, 1 Oct 2000 11:07:02 +0100, Dave <dave@marballs.co.uk> wrote:
> >Thank you for your input. Another basic question I am afraid.
> >
> >I am using someone else's server who has perl installed. Can I assume
they
> >already have these modules on there commercial server because I surely
would
> >not be able to install new modules on my web space providers server. They
> >say they have full cgi-bin support.
> >
>
>
> A good question you should ask this "someone else".
>
>
>
>
> Villy
------------------------------
Date: Thu, 05 Oct 2000 13:41:29 -0700
From: Gordon Vrdoljak <vrdoljak@uclink.berkeley.edu>
Subject: beginner question
Message-Id: <39DCE779.33EDCD90@uclink.berkeley.edu>
Hello,
I was having some trouble with extracting days from the localtime function in
perl. I noticed the following in an example but don't understand it:
$thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];
The best I can see is that the string thisday is assigned to array element 6 of
localtime function and then the weekday is somehow pulled out of this. Can
anyone break it down into smaller steps where I can see how the day is assigned?
Thanks for the help.
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Gordon Ante Vrdoljak Electron Microscope Lab
ICQ 23243541 http://nature.berkeley.edu/~gvrdolja 26 Giannini Hall
vrdoljak@uclink.berkeley.edu UC Berkeley
phone (510) 642-2085 Berkeley CA 94720-3330
fax (510) 643-6207 cell (510) 290-6793
------------------------------
Date: 5 Oct 2000 21:02:56 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: beginner question
Message-Id: <slrn8tp0s1.r4g.trammell@nitz.hep.umn.edu>
On Thu, 05 Oct 2000 13:41:29 -0700, Gordon Vrdoljak
<vrdoljak@uclink.berkeley.edu> wrote:
>I noticed the following in an example but don't understand it:
>
>$thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];
>
>Can anyone break it down into smaller steps where I can see
>how the day is assigned?
$foo = (localtime)[6];
$thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[$foo];
--
John J. Trammell
johntrammell@yahoo.com
------------------------------
Date: Thu, 05 Oct 2000 21:03:00 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: beginner question
Message-Id: <806D5.320903$1h3.7735211@news20.bellglobal.com>
Gordon Vrdoljak <vrdoljak@uclink.berkeley.edu> wrote:
: Hello,
Hullo,
: I was having some trouble with extracting days from the localtime function in
: perl. I noticed the following in an example but don't understand it:
: $thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];
Ok, let's do it in slow-motion:
my @time_info = localtime(); # see perldoc -f localtime
# now @time_info = ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
my $wday = $time_info[6];
# $wday is a number between 0 and 6. yuck. Let's map that to English
my @days = qw/ Sun Mon Tue Wed Thu Fri Sat /;
my $wday_word = $days[ $wday ];
Et voila! :)
Joy,
Yanick
--
($_,$y)=("Yhre lo .kePnarhtretcae\n", '(.) (.)' );
$y=~s/\(/(./gwhile s/$y/$2$1/xg;print; @ !;
" `---' ";
------------------------------
Date: 5 Oct 2000 21:08:51 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: beginner question
Message-Id: <eli$0010051652@qz.little-neck.ny.us>
In comp.lang.perl.misc, Gordon Vrdoljak <vrdoljak@uclink.berkeley.edu> wrote:
> I was having some trouble with extracting days from the localtime function
> in perl. I noticed the following in an example but don't understand it:
>
> $thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];
>
> The best I can see is that the string thisday is assigned to array element
> 6 of localtime function and then the weekday is somehow pulled out of this.
> Can anyone break it down into smaller steps where I can see how the day is
> assigned?
It works something like this:
@days_of_week = (Sun,Mon,Tue,Wed,Thu,Fri,Sat);
@localtime_structure = localtime;
$this_day_number = $localtime_structure[6];
$thisday = $days_of_week[$this_day_number];
But without the other variables.
'(localtime)' is the array structure returned from the localtime
function. '(localtime)[6]' is the day of week number from that
structure. '(Sun,Mon,Tue,Wed,Thu,Fri,Sat)' is the list of days
of the week. '(Sun,Mon,Tue,Wed,Thu,Fri,Sat)[VALUE]' uses VALUE
to select one of the days. In that example the value used is
the somewhat complicated looking '(localtime)[6]'.
Me? I'm just surprised to learn the 'Unquoted string "x" may
clash with future reserved word' warning does not apply to
those days of the week (or apparently many unquoted strings that
are not all lower case).
Elijah
------
quickly makes a JAPH out of that so as not to forget it
------------------------------
Date: Thu, 05 Oct 2000 21:10:48 GMT
From: cfedde@u.i.sl3d.com (Chris Fedde)
Subject: Re: beginner question
Message-Id: <s76D5.166$D4.177712128@news.frii.net>
In article <39DCE779.33EDCD90@uclink.berkeley.edu>,
Gordon Vrdoljak <vrdoljak@uclink.berkeley.edu> wrote:
>Hello,
>I was having some trouble with extracting days from the localtime function in
>perl. I noticed the following in an example but don't understand it:
>
>$thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];
>
The above is a mild example of functional programming.
It's roughly the same as the frag below but without all the temporary
variables.
@a = localtime;
$i = @a[6];
@day = (Sun,Mon,Tue,Wed,Thu,Fri,Sat);
$thisday = $day[$i];
Use substitution to eliminate @a.
$i = localtime[6];
@day = (Sun,Mon,Tue,Wed,Thu,Fri,Sat);
$thisday = $day[$i];
Do the same thing for $i
@day = (Sun,Mon,Tue,Wed,Thu,Fri,Sat);
$thisday = $day[localtime[6]];
Now finish it off by substituting the definition of @day
$thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[localtime[6]];
Hope this helps
chris
--
This space intentionally left blank
------------------------------
Date: 5 Oct 2000 21:11:13 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: beginner question
Message-Id: <slrn8tprjg.ovr.clay@panix2.panix.com>
On Thu, 05 Oct 2000 13:41:29 -0700, Gordon Vrdoljak
<vrdoljak@uclink.berkeley.edu> wrote:
>I was having some trouble with extracting days from the localtime function in
>perl. I noticed the following in an example but don't understand it:
>
>$thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];
>
>The best I can see is that the string thisday is assigned to array element 6 of
>localtime function and then the weekday is somehow pulled out of this. Can
>anyone break it down into smaller steps where I can see how the day is
>assigned?
Break it down:
#!/usr/local/bin/perl
$day = (localtime)[6];
print "$day\n";
$theday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[4];
print "$theday\n";
$thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];
print "$thisday\n";
Result:
4
Thu
Thu
From perldoc:
# 0 1 2 3 4 5 6 7 8
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
The 7th element of the array is going to return a number representing the
weekday. In the example above the value returned is 4.
Now get the 5th element of this list:
(Sun,Mon,Tue,Wed,Thu,Fri,Sat)
0 1 2 3 4 5 6
The 5th element is "Thu".
--
Clay Irving <clay@panix.com>
It's ironic that you would use a language as large as English to express
so small a thought.
- Larry Wall
------------------------------
Date: Thu, 5 Oct 2000 14:30:03 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: beginner question
Message-Id: <MPG.144692b6e34cf2d398ae11@nntp.hpl.hp.com>
In article <39DCE779.33EDCD90@uclink.berkeley.edu> on Thu, 05 Oct 2000
13:41:29 -0700, Gordon Vrdoljak <vrdoljak@uclink.berkeley.edu> says...
> Hello,
Hello, yourself.
> I was having some trouble with extracting days from the localtime function in
> perl. I noticed the following in an example but don't understand it:
>
> $thisday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];
(localtime) Evaluate the localtime function in list context.
The default argument is the current time.
(localtime)[6] Extract the seventh element of the list, which
is the day of the week (Sunday == 0).
qw(Sun Mon Tue Wed Thu Fri Sat)[...]
Use the numerical day of the week to extract
the name from a list of names. I have corrected
the expression so it doesn't use barewords,
which would draw a warning.
$thisday = ... Finally, assign the name.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 05 Oct 2000 16:50:15 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: beginner question
Message-Id: <87snqb0xgo.fsf@limey.hpcc.uh.edu>
>> On Thu, 05 Oct 2000 13:41:29 -0700,
>> Gordon Vrdoljak <vrdoljak@uclink.berkeley.edu> said:
> Hello, I was having some trouble with extracting days
> from the localtime function in perl. I noticed the
> following in an example but don't understand it:
> $thisday =
> (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[(localtime)[6]];
Alternatively (and useful for more complicated date/time
field extractions):
use POSIX 'strftime';
my $weekday = strftime('%a', localtime);
See "perldoc POSIX" and your system's strftime()
documentation.
hth
t
--
Namaste!
And an "oogabooga" to you too!
-- Homer Simpson
------------------------------
Date: Thu, 5 Oct 2000 17:11:19 -0400
From: "Paul Kolonay" <kolonay@micro.ti.com>
Subject: Can Perl extension on UNIX be C++ ?
Message-Id: <8riqi8$i55$1@tilde.csc.ti.com>
Can a perl extension be compiled as C++ on uinx (solaris 2.6) ?
I am having some problems with a module that was compiled as c++
and it has been suggested that languages cannot be mixed (i.e you cannot
mix a c executable with a c++ shared lib).
It appears that the C++ runtimes are not getting loaded because main is
in perl ( written in C ).
I feel sure that this can be done, but would like some confirmation.
This is not a problem on WIN32 platform.
Thanks
Paul
------------------------------
Date: Thu, 05 Oct 2000 20:39:35 GMT
From: "Smitty" <jpsmith@mediom.qc.ca>
Subject: Can't lock error
Message-Id: <01c02f0d$32522b20$332571d8@jpsmith>
Server : Apache/1.2.5 (SunOS 5.4)
Perl version : 5.001
Gateway_interface : CGI/1.1
----------------------------------------------
The problem: I'm trying to install a perl script that read and write to a
dat file and a html file (updating links process)... permissions are ok and
double checked.
But the script generates the following after having written the .dat and
before updating the .html file:
The following error occurred : can't lock file
(/netra/home/.../index.html)
I have installed the same on netfirms.com (perl 5.003) and everything is
running without error.
Do you have an idea of how to fix that problem. I cannot run that script
from netfirms.com because of the ads...
Thanks in advance
JPSmith (newbie with perl)
------------------------------
Date: Thu, 5 Oct 2000 13:47:09 -0500
From: buck_naked@NOiname.SPAMcom
Subject: Changing STDOUT
Message-Id: <Pine.GSO.4.21.0010051345440.27157-100000@login12>
Let's say I have a program where I change STDOUT in order to pipe it
through a pager or something:
open STDOUT "| /usr/local/bin/less";
Now, let's say I want to go back to the normal setting for STDOUT in
the same program. How would I do that?
---
Mark, Master of the Obvious
buck_naked@iname.com
"Why can't the Maples be happy in their shade?"
------------------------------
Date: Thu, 05 Oct 2000 20:10:55 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Changing STDOUT
Message-Id: <4vnpts037hrkd4bnjdq5omo9ulesk61lih@4ax.com>
buck_naked@NOiname.SPAMcom wrote:
>open STDOUT "| /usr/local/bin/less";
>
>Now, let's say I want to go back to the normal setting for STDOUT in
>the same program. How would I do that?
Why don't you do:
open LESS, "| /usr/local/bin/less";
select LESS;
So LESS is the default output handle.
select STDOUT;
and you're back to normal.
You can also dup STDOUT, and dup it back in the end.
OPEN SAVEOUT, ">&STDOUT";
open STDOUT, "...";
...
OPEN STDOUT, ">&SAVEOUT";
--
Bart.
------------------------------
Date: Thu, 05 Oct 2000 19:39:39 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Changing STDOUT
Message-Id: <%N4D5.320687$1h3.7732846@news20.bellglobal.com>
buck_naked@noiname.spamcom wrote:
: Let's say I have a program where I change STDOUT in order to pipe it
: through a pager or something:
: open STDOUT "| /usr/local/bin/less";
: Now, let's say I want to go back to the normal setting for STDOUT in
: the same program. How would I do that?
open STDOUT, ">-" or die "Ouch. Can't open stdout: $!\n";
Joy,
Yanick
--
($_,$y)=("Yhre lo .kePnarhtretcae\n", '(.) (.)' );
$y=~s/\(/(./gwhile s/$y/$2$1/xg;print; @ !;
" `---' ";
------------------------------
Date: Thu, 05 Oct 2000 20:25:23 GMT
From: amy_v@my-deja.com
Subject: counter problem HELP
Message-Id: <8rio39$nk7$1@nnrp1.deja.com>
Hy all,
I've had a CGI script that has to display a counter on my web page. The
program works fine creating a file in the cgi-bin directory on my
server. I've tried to put the counter on my page using an image with
src=http://my server/cgi-bin/counter.pl, but it doen't work. Also, with
a right-click on the image I can see the counter opened in a new window,
but is not what I want.What should I do to have it on my page???
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 5 Oct 2000 13:01:37 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: date conversion
Message-Id: <MPG.14467dfe8f8dae7698ae0e@nntp.hpl.hp.com>
In article <8ri2q8$40b$1@nnrp1.deja.com> on Thu, 05 Oct 2000 14:22:10
GMT, tjmurphy9677@my-deja.com <tjmurphy9677@my-deja.com> says...
> In article <xl_C5.7996$4i5.408571@typhoon2.ba-dsg.net>,
> "Yi Li" <heisyili@bellatlantic.net> wrote:
> > I have a date/time like this:
> >
> > 03/Sep/2000:00:00:33
> >
> > How can I convert this to the number of seconds since mid night
> 1/1/1970?
> >
> thing something like this will do it (haven't tested it)
Then why post untested code, instead of simply referring to the FAQ?
perlfaq4: "How can I take a string and turn it into epoch seconds?"
> add to top of file (below #!perl)
> use Time::Local;
>
> then use this to get epoc time (seconds since jan 1 1970
> $mdaymon=substr("03/Sep/2000:00:00:33",0,7);
> $therest=substr("03/Sep/2000:00:00:33",7,13);
> ($mday,mon)=split(/\//,$mdaymon);
> ($year,hour,$min,$sec)=split(/[:]/,$therest);
> $epoc_error_time=timelocal($sec,$min,$hour,$mday,$mon,$year);
^^^^^
Well, you got that part right (though I think you meant
'epoch_era_time').
timelocal() doesn't accept a string as the value for the month argument.
Either convert the string to a number, properly offset from January ==
0; or use a module referred to in the FAQ.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 05 Oct 2000 12:59:49 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Does anyone have a jed mode for perl
Message-Id: <39DCDDB5.1AA48943@vpservices.com>
Anders Lund wrote:
>
> Does anyone have a jed mode for perl??
Try the Hillbillies::Beverly module.
--
Jeff
------------------------------
Date: Thu, 05 Oct 2000 21:24:40 GMT
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: Forking, Exiting, and Timing out within an Eval
Message-Id: <sk6D5.23788$td5.4311996@news1.rdc2.pa.home.com>
"post_to_group" <already_seen@my-deja.com> wrote in message
news:8rfrpc$b15$1@nnrp1.deja.com...
> Any ideas why the children processes seem to
> continue with the rest of the script outside the forked part? What am I
> doing wrong? The script works pretty well going to each host once, but
Try sprinkling some
print "Line number ", __LINE__ , ": my PID is $$\n";
statements so you know how many processess are executing at any given point
in time in your code. This should give you enough diagnostics to figure out
the bug
> And lastly, I was wondering if it is possible to use exec instead of
> system? I tried exec because there were some good examples using exec,
> but then the alarm never happens.
exec() will completely replace the current process with the new process,
while system() forks off a child process. Perhaps your confusion over
system() and exec() (combined with several fork()'s) is causing your process
headaches -
--Ben Kennedy
------------------------------
Date: Thu, 05 Oct 2000 20:47:10 GMT
From: Michael Segulja <michael.segulja@sgi-lsi.com>
Subject: Help processing files in a directory
Message-Id: <8ripcb$ors$1@nnrp1.deja.com>
I have searched Deja for the answer to my problem, but I haven't been
able to find it. I was able to get a little further along based on
some posting similar to this question, but I'm not quite there.
Hopefully somebody can help me. Here's what I'm trying to do:
I want to list the tag info for a list of MP3 files. I have a
directory called /var/audio/mp3 (I'm using Linux for this by the way),
and under that is a directory for the artist, and then a directory for
the album, and then each individual song. I have all the code I need
to read the tag info and put it into a database as long as I tell the
script what the filename is. I want to be able to do something
like 'dir -R /var/audio/mp3 | grep .mp3' to list only the mp3 files
under /var/audio/mp3. The code I have so far will only list the
directories under /var/audio/mp3. Here's what I have:
#!/usr/bin/perl -w
use diagnostics;
use strict;
print "\n" x 3;
my $dir = "/var/audio/mp3";
chdir $dir or die "Couldn't change to $dir. $!\n";
opendir DIR,'.' or die "Couldn't open $dir. $!\n";
my @dirs = grep((!/\.mp3/ && -d), readdir(DIR));
print "@dirs\n";
I tried using 'my @dirs=grep((!/\.mp3/ && -f), readdir(DIR));' but that
gives me nothing. Right now, I'm just trying to get it to give me a
directory listing of the $dir variable, and each subdirectory under
that of only *.mp3 files.
I'm a newbie here (as if you couldn't tell) and I'm using this project
to learn the Perl language. I really appreciate any help, and I
apoligize for asking something that's been through Usenet already. I'm
just too slow sometimes I think!! :)
Thanks again,
Michael
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 5 Oct 2000 21:36:32 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: Help processing files in a directory
Message-Id: <8ris90$rfa@gap.cco.caltech.edu>
In article <8ripcb$ors$1@nnrp1.deja.com>,
Michael Segulja <michael.segulja@sgi-lsi.com> wrote:
>I want to list the tag info for a list of MP3 files. I have a
>directory called /var/audio/mp3 (I'm using Linux for this by the way),
>and under that is a directory for the artist, and then a directory for
>the album, and then each individual song. I have all the code I need
>to read the tag info and put it into a database as long as I tell the
>script what the filename is. I want to be able to do something
>like 'dir -R /var/audio/mp3 | grep .mp3' to list only the mp3 files
>under /var/audio/mp3.
If you're trying to do "something like dir -R", then you almost
certainly want to use the File::Find module to do it in Perl.
It should already be installed as part of your Perl installation --
do a perldoc File::Find to see the documentation.
>I tried using 'my @dirs=grep((!/\.mp3/ && -f), readdir(DIR));' but that
>gives me nothing.
Remember that readdir only returns the bare filename, and when you
pass that to -f, it will look in the current directory. To use
the -X tests with readdir, you usually need to do -f "$dir/$_".
But as I said, I think File::Find is more likely to be what you need.
To find all the .mp3 files, you can use something like
use File::Find;
my @files;
find sub { push @files, $File::Find::name if /\.mp3\z/ && -f; },
"/var/audio/mp3";
print "@files\n";
-- Gary Ansok
------------------------------
Date: 5 Oct 2000 19:07:06 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: How? Read a file from another server?
Message-Id: <slrn8tpkaq.8n6.clay@panix2.panix.com>
On Thu, 05 Oct 2000 11:00:15 -0700, Godzilla! <godzilla@stomp.stomp.tokyo>
wrote:
>> Godzilla! wrote an excellent article:
Godzilla wrote a fucked up rambling of misinformation.
>You are so foolish to actually think I would
>lend credibility to your mule manure.
What's wrong with you? You posted absolute nonsense and I took the time to
benchmark your "more efficient" method and the generally accepted "correct"
method. Your method is horribly inefficient. So what do you do? -- You act
like a kid in a school yard play ground and call me a fool talking horse
do-do...
How pathetic.
< plonk >
--
Clay Irving <clay@panix.com>
I think of life as a good book. The further you get into it, the more it
begins to make sense.
- Harold S. Kushner
------------------------------
Date: 5 Oct 2000 15:48:48 -0400
From: darkon@one.net (David Wall)
Subject: Re: HTML::Parser question
Message-Id: <8FC4A6C97darkononenet@206.112.192.118>
ian.walker@homme.com (Ian Walker) wrote in <39dca504.98833755@news>:
>I have tried to RTFM and after alot of looking I still don't get it...
>
>what I have is a variable, we will call it, $html_here
>in that variable is an entire html file, i was told that HTML::Parser
>can split the file up into sections separated by the tags, and clean
>up all tags. So <img
>xyz>
>
>will become <img xyz> (no carage return).
>
>so is it possible to take $html_here and output it to a new variable
>all cleaned up??
>
>Thanks for any info.
If all you're wanting is a program that will clean and pretty-print your
HTML, you might try the "tidy" program from the W3C:
http://www.w3.org/People/Raggett/tidy/. But then it's no longer a Perl
problem... and ruins the fun of writing your own. :-)
--
David Wall
darkon@one.net
------------------------------
Date: Thu, 05 Oct 2000 21:31:56 GMT
From: jdaves@gilanet.com
Subject: MIME::Entity question
Message-Id: <8ris0d$rcs$1@nnrp1.deja.com>
OK, I'm that close to solving this.
I'm writing yet another web-based email reader, using MIME::Parser (and
associated stuff) and Mail::POP3Client, running on linux.
I won't give all the code here, but I will give what I think are
relevent sections.
Everything works fine, I send jpegs and browsers read & show them just
fine. The problem is that, when I try to save files to a Windoze
computer, garbage comes across. When I try to ftp the file directly from
the temporary directory, garbage comes across. File size is different
between the original and the MIME copy.
Anybody have any ideas? I suspect something to do with the write $_
statements, but I don't really know what to do to fix it.
#################################################
# Send mail:
my $top = MIME::Entity->build(From=>$from, To, CC, etc,
Type=>"Multipart/mixed")
my $attach = param('ATTACH'); #From a CGI filefield() call
if ($attach) {
mkpath($temp_path, 0, 0777) if (!(-d $temp_path));
my $file_name = $temp_path . "/" . $name;
if (open FILE, ">" . $file_name) {
while (<$attach>) { print FILE $_ };
}
$top->attach(Path => $file_name,
Type=> whatever,
Encoding=>"base_64");
}
$top->send("sendmail");
unlink $file_name;
############################
#################
# Read mail chunk
my @mail = $pop->Retrieve($msg);
# I need the next line to make CR/LF's print on text sections.
foreach(@mail) ($_ =! s/$/\n/ };
my $entity = $parser->parse_data(\@mail);
for my $i (0 .. $entity->parts - 1) {
my $ent = $entity->parts($i);
mkpath($temp_path, 0, 0777);
my $file_name = $path . "/" . $name;
print "<a href=\"$href\">$name</a>";
if (open FILE, ">" . $file_name) {
if ($io = $ent->open('r')) {
while (define($_ = $io->getline)) { print FILE $_ };
$io->close;
$ent->purge;
}
}
}
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 05 Oct 2000 19:22:35 GMT
From: willowjenkins@hotmail.com (Willow)
Subject: Re: new
Message-Id: <39dcd346.160641760@news.rsc.raytheon.com>
<sarcasm>
Search the internet.
</sarcasm>
Actually you may want to start at a few of these places.
http://www.4images.com/ntperl/
http://www.geocities.com/SiliconValley/Park/8312/
http://www.activestate.com/
Willow
<sarcasm>
~ newsgroups are mostly for people to tell you about FAQ and search
engines, they are not a resource of information ~
</sarcasm>
------------------------------
Date: Thu, 5 Oct 2000 16:42:37 -0400
From: "Gary P" <gp@no.thanks>
Subject: Re: new
Message-Id: <NC5D5.310$2f7.166@newsfeed.slurp.net>
get o'reilly's "learning perl", then get o'reilly's "programming perl"
"Joeri Grandry" <joeri.grandry@skynet.be> wrote in message
news:39DBD528.943FC3BD@skynet.be...
> hi i have never used perl before, what is the best way to start with it
> any program i need or so
>
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 4531
**************************************