[23952] in Perl-Users-Digest
Perl-Users Digest, Issue: 6153 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 18 14:05:49 2004
Date: Wed, 18 Feb 2004 11:05:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 18 Feb 2004 Volume: 10 Number: 6153
Today's topics:
Re: can s/// return a new value, rather than modifying <bik.mido@tiscalinet.it>
Re: can s/// return a new value, rather than modifying <tassilo.parseval@rwth-aachen.de>
Re: can s/// return a new value, rather than modifying <nobull@mail.com>
Re: can s/// return a new value, rather than modifying <noreply@gunnar.cc>
Re: can s/// return a new value, rather than modifying <usenet@morrow.me.uk>
Re: Can't build SNMP... <usenet@morrow.me.uk>
Re: Can't build SNMP... <ggershSNACK@CAKEctc.net>
Re: Can't build SNMP... <usenet@morrow.me.uk>
Case-insensitive match for File::Find (Prabh)
Re: Case-insensitive match for File::Find <usenet@expires03-2004.tinita.de>
commandline version of this script. (NNTP)
Re: configure, WIN32 <tmohr@s.netic.de>
Re: configure, WIN32 <usenet@morrow.me.uk>
Re: Date::Manip using system libraries? <usenet@morrow.me.uk>
how to cut a text file in perl (Joseph)
Re: how to cut a text file in perl <HeWillRejoice@yahoo.com>
Re: how to cut a text file in perl <kkeller-usenet@wombat.san-francisco.ca.us>
Re: how to cut a text file in perl <nobull@mail.com>
Image::magick error <sg@g2group.co.uk>
Re: Image::magick error <usenet@morrow.me.uk>
Re: Listbox and passing entries <kkeller-usenet@wombat.san-francisco.ca.us>
Re: Listbox and passing entries <a@b.com>
Re: mac ftp <jgibson@mail.arc.nasa.gov>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 18 Feb 2004 15:57:10 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: can s/// return a new value, rather than modifying it's input argument?
Message-Id: <ocu630l2mpeci62gljbrq0b7m3f7lgi5qu@4ax.com>
On 17 Feb 2004 22:29:30 -0800, wkeese@yahoo.com (Bill Keese) wrote:
>modifies input-string according to pattern and replacement. But is
>there any similar function which returns a new string, rather than
>updating input-string?
>
>For example, instead of doing this:
>
>($newLetter = $oldLetter) =~ s/Mister/Mr./;
>
>Can I do something like this?
>
> $newLetter = ($oldLetter ~ s/Mister/Mr./) ;
You can do some tricks to that effect. Other than waht you've already
been suggested, just two more WTDI:
#!/usr/bin/perl
use strict;
use warnings;
my $old="foo bar baz\n";
my $new=do { local $_=$old;
s/b\w+\b/$&$&/g;
$_ };
print $old, $new;
__END__
or
#!/usr/bin/perl
use strict;
use warnings;
my $old="foo bar baz\n";
my $new=sub { local $_=shift;
s/b\w+\b/$&$&/g;
$_ }->($old);
print $old, $new;
__END__
and as usual you have a virtually unlimited number of possible
variations...
Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
------------------------------
Date: 18 Feb 2004 15:55:30 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: can s/// return a new value, rather than modifying it's input argument?
Message-Id: <c101ti$qg8$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Gunnar Hjalmarsson:
> Tassilo v. Parseval wrote:
>> Also sprach James Taylor:
>>> Gunnar Hjalmarsson wrote:
>>>>
>>>> ...you can of course write your own function:
>>>>
>>>> sub replace {
>>>> my ($str, $pat, $rpl) = @_;
>>>> $str =~ s/$pat/$rpl/;
>>>> $str
>>>> }
>>>>
>>>> my $newLetter = replace($oldLetter, qr/Mister/, 'Mr.');
>>>
>>> What's the benefit of using the qr// quoting construct here?
>>>
>>> Is there any way for the subroutine to detect that it has been
>>> passed a regex instead of a plain string?
>>
>> Yes, sure:
>>
>> sub replace {
>> my ($str, $pat, $rpl) = @_;
>> print "Regexp passed\n" if ref($pat) eq "Regexp";
>> ...
>> }
>
> Interesting! I was obviously wrong when saying that qr// returns a
> string, even if it looks that way when you print the return value.
It returns an object blessed into the package Regexp. You can print this
object because it sort of overloads stringification. I am not sure that
this is technically correct. At least it is what happens from the point
of view of the programmer.
For instance you can write this:
sub Regexp::match_against { return $_[1] =~ /$_[0]/ }
print qr/foo/->match_against("foobar");
__END__
1
> Still confused:
> - Does qr// return a reference to a regular expression?
Hard to say. Neither perlop nor perlre mention anywhere that the return
value of qr// behaves like an object.
> - Is this use of the ref() function documented anywhere?
Probably not. It is just a consequence of the fact that qr// returns
something reference-ish.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 18 Feb 2004 18:42:36 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: can s/// return a new value, rather than modifying it's input argument?
Message-Id: <u9vfm4fcv7.fsf@wcl-l.bham.ac.uk>
Gregory Toomey <nospam@bigpond.com> writes:
> sub apply (&$) {
> local $_ = $_[1];
> $_[0]->();
> $_;
> }
I first coined the name 'apply' for this function in John Lin's
classic asking of this question "Idiom: the expression of a copied &
substituted string" back in April 2001
http://groups.google.com/groups?threadm=9boir8%242ra%40netnews.hinet.net
I don't like Gregory Toomey's varition on my original suggestion...
Firstly you should never say "local $_" - it has some really nasty
action-at-a-distance problems when $_ happens to be aliased to an
element of a tied aggregate. Localising of $_ should be done with
"for" or "map".
Secondly I think it makes more sense for &apply to work in a list
context too.
sub apply (&@) {
my $action = shift;
&$action for my @values = @_;
wantarray ? @values : $values[-1];
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 18 Feb 2004 14:52:43 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: can s/// return a new value, rather than modifying it's input argument?
Message-Id: <c0vrfb$1b984g$1@ID-184292.news.uni-berlin.de>
Tassilo v. Parseval wrote:
> Also sprach James Taylor:
>> Gunnar Hjalmarsson wrote:
>>>
>>> ...you can of course write your own function:
>>>
>>> sub replace {
>>> my ($str, $pat, $rpl) = @_;
>>> $str =~ s/$pat/$rpl/;
>>> $str
>>> }
>>>
>>> my $newLetter = replace($oldLetter, qr/Mister/, 'Mr.');
>>
>> What's the benefit of using the qr// quoting construct here?
>>
>> Is there any way for the subroutine to detect that it has been
>> passed a regex instead of a plain string?
>
> Yes, sure:
>
> sub replace {
> my ($str, $pat, $rpl) = @_;
> print "Regexp passed\n" if ref($pat) eq "Regexp";
> ...
> }
Interesting! I was obviously wrong when saying that qr// returns a
string, even if it looks that way when you print the return value.
Still confused:
- Does qr// return a reference to a regular expression?
- Is this use of the ref() function documented anywhere?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 18 Feb 2004 17:57:09 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: can s/// return a new value, rather than modifying it's input argument?
Message-Id: <c1091l$7gh$2@wisteria.csv.warwick.ac.uk>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> James Taylor wrote:
> > In article <c0v2bs$1bmfg6$1@ID-184292.news.uni-berlin.de>,
> > Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> >
> >>...you can of course write your own function:
> >>
> >> sub replace {
> >> my ($str, $pat, $rpl) = @_;
> >> $str =~ s/$pat/$rpl/;
> >> $str
> >> }
> >>
> >> my $newLetter = replace($oldLetter, qr/Mister/, 'Mr.');
> >
> > What's the benefit of using the qr// quoting construct here?
>
> None that I'm aware of in this simple example, but it might be useful
> to pass modifiers etc.
It's faster. Perl doesn't need to recompile the regex in $pat at run-time.
> > Is there any way for the subroutine to detect that it has been
> > passed a regex instead of a plain string?
>
> Don't think so. It is a plain string, btw. In this case it is:
> '(?-xism:Mister)'.
It's not quite a 'plain' string: it has compiled-regex magic attached
to it.
Ben
--
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
-Assyrian stone tablet, c.2800 BC ben@morrow.me.uk
------------------------------
Date: Wed, 18 Feb 2004 18:06:08 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Can't build SNMP...
Message-Id: <c109ig$7gh$4@wisteria.csv.warwick.ac.uk>
Greg G <ggershSNACK@CAKEctc.net> wrote:
>
> I get the following when trying to install the SNMP-4.2.0 into perl
> 5.8.2 on a Solaris 7 host. Note that I don't want to use Net::SNMP as I
> can't quite decipher the docs and I plan to migrate to SNMP::Multi after
> I migrate some old code that's making snmpget system calls.
>
>
> # perl Makefile.PL
> WARNING: MAN3PODS takes a hash reference not a string/number.
> Please inform the author.
> Checking if your kit is complete...
> Looks good
> Processing hints file hints/solaris.pl
> Can't use string ("SNMP") as a HASH ref while "strict refs" in use at
> /usr/local/lib/perl5/5.8.2/ExtUtils/MM_Unix.pm line 503.
This is a bug in the Makefile.PL of SNMP.pm... not a good sign. What
does the line containing MAN3PODS say?
Ben
--
If I were a butterfly I'd live for a day, / I would be free, just blowing away.
This cruel country has driven me down / Teased me and lied, teased me and lied.
I've only sad stories to tell to this town: / My dreams have withered and died.
ben@morrow.me.uk <=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=> (Kate Rusby)
------------------------------
Date: Wed, 18 Feb 2004 13:22:38 -0500
From: Greg G <ggershSNACK@CAKEctc.net>
Subject: Re: Can't build SNMP...
Message-Id: <MYudnc1IjJ_zMK7dRVn-sw@ctc.net>
Ben Morrow wrote:
> Greg G <ggershSNACK@CAKEctc.net> wrote:
>
>>I get the following when trying to install the SNMP-4.2.0 into perl
>>5.8.2 on a Solaris 7 host. Note that I don't want to use Net::SNMP as I
>>can't quite decipher the docs and I plan to migrate to SNMP::Multi after
>>I migrate some old code that's making snmpget system calls.
>>
>>
>># perl Makefile.PL
>>WARNING: MAN3PODS takes a hash reference not a string/number.
>> Please inform the author.
>>Checking if your kit is complete...
>>Looks good
>>Processing hints file hints/solaris.pl
>>Can't use string ("SNMP") as a HASH ref while "strict refs" in use at
>>/usr/local/lib/perl5/5.8.2/ExtUtils/MM_Unix.pm line 503.
>
>
> This is a bug in the Makefile.PL of SNMP.pm... not a good sign. What
> does the line containing MAN3PODS say?
my %Params = (
NAME => 'SNMP',
dist => { SUFFIX => "gz", COMPRESS => "gzip -9f"},
MAN3PODS => 'SNMP', # Pods will be built by installman.
XSPROTOARG => '-noprototypes', # XXX remove later?
VERSION_FROM => 'SNMP.pm',
realclean => { FILES => 'host' },
);
I would never have correlated that error to this line. Thanks. I've
put curly braces around the 'SNMP' on the MAN3PODS line. That has fixed
the makefile generation. Unforunately, it still doesn't build.
AutoSplitting blib/lib/SNMP.pm (blib/lib/auto/SNMP)
/usr/bin/perl /usr/local/lib/perl5/5.8.2/ExtUtils/xsubpp -noprototypes
-typemap /usr/local/lib/perl5/5.8.2/ExtUtils/typemap -typemap typemap
SNMP.xs > SNMP.xsc && mv SNMP.xsc SNMP.c
/opt/SUNWspro/bin/cc -c -I/usr/local/include -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O -DVERSION=\"4.2.0\"
-DXS_VERSION=\"4.2.0\" -KPIC
"-I/usr/local/lib/perl5/5.8.2/sun4-solaris/CORE" SNMP.c
"SNMP.xs", line 224: invalid token in #define macro parameters: ...
"SNMP.xs", line 824: warning: argument #3 is incompatible with prototype:
prototype: pointer to uint :
"/usr/local/include/ucd-snmp/mib.h", line 274
argument : pointer to int
"SNMP.xs", line 998: warning: argument #4 is incompatible with prototype:
prototype: pointer to int : "SNMP.xs", line 141
argument : pointer to uint
"SNMP.xs", line 1450: undefined symbol: _debugx
"SNMP.xs", line 1451: warning: improper pointer/integer combination: arg #1
and so on.
Wheee! :)
-Greg G
------------------------------
Date: Wed, 18 Feb 2004 18:52:31 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Can't build SNMP...
Message-Id: <c10c9f$a0u$5@wisteria.csv.warwick.ac.uk>
Greg G <ggershSNACK@CAKEctc.net> wrote:
> Ben Morrow wrote:
> > Greg G <ggershSNACK@CAKEctc.net> wrote:
> >
> >>I get the following when trying to install the SNMP-4.2.0 into perl
> >>5.8.2 on a Solaris 7 host. Note that I don't want to use Net::SNMP as I
> >>can't quite decipher the docs and I plan to migrate to SNMP::Multi after
> >>I migrate some old code that's making snmpget system calls.
> >>
> >>
> >># perl Makefile.PL
> >>WARNING: MAN3PODS takes a hash reference not a string/number.
> >> Please inform the author.
> >>Checking if your kit is complete...
> >>Looks good
> >>Processing hints file hints/solaris.pl
> >>Can't use string ("SNMP") as a HASH ref while "strict refs" in use at
> >>/usr/local/lib/perl5/5.8.2/ExtUtils/MM_Unix.pm line 503.
> >
> >
> > This is a bug in the Makefile.PL of SNMP.pm... not a good sign. What
> > does the line containing MAN3PODS say?
>
> my %Params = (
> NAME => 'SNMP',
> dist => { SUFFIX => "gz", COMPRESS => "gzip -9f"},
> MAN3PODS => 'SNMP', # Pods will be built by installman.
> XSPROTOARG => '-noprototypes', # XXX remove later?
> VERSION_FROM => 'SNMP.pm',
> realclean => { FILES => 'host' },
> );
>
> I would never have correlated that error to this line. Thanks. I've
> put curly braces around the 'SNMP' on the MAN3PODS line.
Better would be to delete both that line and the 'dist' line: both are
imply setting the default options.
> That has fixed
> the makefile generation. Unforunately, it still doesn't build.
>
> AutoSplitting blib/lib/SNMP.pm (blib/lib/auto/SNMP)
> /usr/bin/perl /usr/local/lib/perl5/5.8.2/ExtUtils/xsubpp -noprototypes
> -typemap /usr/local/lib/perl5/5.8.2/ExtUtils/typemap -typemap typemap
> SNMP.xs > SNMP.xsc && mv SNMP.xsc SNMP.c
> /opt/SUNWspro/bin/cc -c -I/usr/local/include -I/usr/local/include
> -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O -DVERSION=\"4.2.0\"
> -DXS_VERSION=\"4.2.0\" -KPIC
> "-I/usr/local/lib/perl5/5.8.2/sun4-solaris/CORE" SNMP.c
> "SNMP.xs", line 224: invalid token in #define macro parameters: ...
> "SNMP.xs", line 824: warning: argument #3 is incompatible with prototype:
> prototype: pointer to uint :
> "/usr/local/include/ucd-snmp/mib.h", line 274
> argument : pointer to int
> "SNMP.xs", line 998: warning: argument #4 is incompatible with prototype:
> prototype: pointer to int : "SNMP.xs", line 141
> argument : pointer to uint
> "SNMP.xs", line 1450: undefined symbol: _debugx
> "SNMP.xs", line 1451: warning: improper pointer/integer combination: arg #1
Oh dear oh dear oh dear oh dear... I'd recommend using something else
unless you fancy some XS debugging fun. You could try contacting the
author.
Ben
--
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
* ben@morrow.me.uk *
------------------------------
Date: 18 Feb 2004 08:40:35 -0800
From: Prab_kar@hotmail.com (Prabh)
Subject: Case-insensitive match for File::Find
Message-Id: <e7774537.0402180840.4075d39@posting.google.com>
Hello all,
Just wanted to check if theres a 'case-insensitive' option while
searching for an element using File::Find. I'm going through the
module docs and cant see any mention to case-sensitivity.
I know I need to search for "foo", but dont know if its present as
"Foo" or "foo"....
For now, I'm using this very time-consuming cmd-line Unix find.
<%> find /home/abc123 | grep -i foo
Thanks for your time,
Prab
------------------------------
Date: 18 Feb 2004 17:35:24 GMT
From: Tina Mueller <usenet@expires03-2004.tinita.de>
Subject: Re: Case-insensitive match for File::Find
Message-Id: <c107os$1cfl79$2@ID-24002.news.uni-berlin.de>
Prabh wrote:
> Just wanted to check if theres a 'case-insensitive' option while
> searching for an element using File::Find. I'm going through the
> module docs and cant see any mention to case-sensitivity.
well, how do you search an element at the moment?
just compare the filename lowercase to your string, like:
... if 'foo' eq lc $_;
> For now, I'm using this very time-consuming cmd-line Unix find.
> <%> find /home/abc123 | grep -i foo
probably you want to add the option -iname; it's documented in the
find man page. and there's find2perl which translates your find-statement
to perl.
hth, tina
--
http://www.tinita.de/ http://www.perlquotes.de/ http://www.darkdance.net/
Enter the Doors of P e r c e p t i o n
http://www.perl-community.de/ http://berlin.pm.org/
- the above mail address expires end of march 2004 -
------------------------------
Date: 18 Feb 2004 10:50:49 -0800
From: news8080@yahoo.com (NNTP)
Subject: commandline version of this script.
Message-Id: <110fc16.0402181050.1a88d36a@posting.google.com>
#!/usr/bin/perl
use Validate::Net;
if ( Validate::Net->ip($ARGV[0]))
{
print "valid";
exit 0;
}
print "invalid";
#--done
is it even doable?
------------------------------
Date: Wed, 18 Feb 2004 19:06:50 +0100
From: Torsten Mohr <tmohr@s.netic.de>
Subject: Re: configure, WIN32
Message-Id: <c109jq$4lq$1@schleim.qwe.de>
Hi,
>> README.win32 (you *have* read it?) says you need to use dmake and the
>> makefile in win32/. Looking at it, you should (maybe) be able to get a
>> static build by unpacking the extensions you need under ext/ and then
>> changing the definition of STATIC_EXT in makefile.mk to include them
>> all. DYNAMIC_EXT should be empty.
just today i've tried.
Using "dmake" works fine, but i think i should somehow define that
i don't want to generate a DLL, just a LIB.
I don't know if this can be done with changes only in the Makefile,
i think that every code for a DLL also needs to contain "DllMain",
correct?
So just changing the Makefile to generate a LIB instead of a DLL
won't work, correct?
I also need to tell XS and other tools to generate code that compiles
for a LIB? How can i do that?
I also need to call the xs_init() of all the modules that are linked
into the LIB? Do i need to do this manually or is there a better way?
Thanks for hints,
Torsten.
------------------------------
Date: Wed, 18 Feb 2004 18:57:02 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: configure, WIN32
Message-Id: <c10chu$a0u$6@wisteria.csv.warwick.ac.uk>
Torsten Mohr <tmohr@s.netic.de> wrote:
> Hi,
>
> > I (Ben Morrow) wrote:
> >> README.win32 (you *have* read it?) says you need to use dmake and the
> >> makefile in win32/. Looking at it, you should (maybe) be able to get a
> >> static build by unpacking the extensions you need under ext/ and then
> >> changing the definition of STATIC_EXT in makefile.mk to include them
> >> all. DYNAMIC_EXT should be empty.
>
> just today i've tried.
>
> Using "dmake" works fine, but i think i should somehow define that
> i don't want to generate a DLL, just a LIB.
This is what STATIC_EXT should do for you.
> I also need to tell XS and other tools to generate code that compiles
> for a LIB? How can i do that?
Everything gets its info from the perl binary it uses, also from its
Config.pm. If both those are correct, you should be fine (assuming
static builds work on Win32 at all).
> I also need to call the xs_init() of all the modules that are linked
> into the LIB? Do i need to do this manually or is there a better way?
See ExtUtils::Embed.
Ben
--
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else * ben@morrow.me.uk
------------------------------
Date: Wed, 18 Feb 2004 18:04:03 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Date::Manip using system libraries?
Message-Id: <c109ej$7gh$3@wisteria.csv.warwick.ac.uk>
Sandman <mr@sandman.net> wrote:
> I am experiencing oddities with my system.
>
> How come this doesn't work:
>
> select unix_timestamp("1925-01-01");
> -> 0
>
> But this does:
>
> perl -e 'use Date::Manip; print UnixDate("1925-01-01", "%s");'
> -> -1420074000
Negative epoch times are not valid: you should not use them. That
Date::Manip returns them here rather than returning an error I would
consider a bug.
Use some other time format, such as the YYYY-MM-DD you started with.
Ben
--
"If a book is worth reading when you are six, * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis
------------------------------
Date: 18 Feb 2004 06:43:21 -0800
From: jcharth@hotmail.com (Joseph)
Subject: how to cut a text file in perl
Message-Id: <2f2b8b0b.0402180643.6604d329@posting.google.com>
hi i have a log file that it is increasing to big, how can i keep this
file of
a certain size, in other words, how can i make sure that the file is
only 200 lines long and delete the first lines if longer. i think it
would be easier to write this in a shell script. but i have no idea
in perl. can anyone tell me how to print the last 200 lines of a file
and overwrite the ssame file. thanks.
------------------------------
Date: Wed, 18 Feb 2004 10:28:59 -0500
From: boyd <HeWillRejoice@yahoo.com>
Subject: Re: how to cut a text file in perl
Message-Id: <%wLYb.215$dU3.73@fe01.usenetserver.com>
Joseph wrote:
> hi i have a log file that it is increasing to big, how can i keep this
> file of
> a certain size, in other words, how can i make sure that the file is
> only 200 lines long and delete the first lines if longer. i think it
> would be easier to write this in a shell script. but i have no idea
> in perl. can anyone tell me how to print the last 200 lines of a file
> and overwrite the ssame file. thanks.
There are many ways. A straight-forward way:
Let the logfile be named 'log'.
open I, "<log";
my @lines = <I>;
close I;
open O, ">log";
my $numlines = scalar @lines;
for my $line(@lines[$numlines-200 .. $numlines-1]) {
print O $line;
}
Boyd
------------------------------
Date: Wed, 18 Feb 2004 07:47:29 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: how to cut a text file in perl
Message-Id: <he101c.kq9.ln@goaway.wombat.san-francisco.ca.us>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On 2004-02-18, Joseph <jcharth@hotmail.com> wrote:
> hi i have a log file that it is increasing to big, how can i keep this
> file of
> a certain size, in other words, how can i make sure that the file is
> only 200 lines long and delete the first lines if longer. i think it
> would be easier to write this in a shell script. but i have no idea
> in perl. can anyone tell me how to print the last 200 lines of a file
> and overwrite the ssame file. thanks.
This isn't a Perl answer, but you should investigate logrotate.
- --keith
- --
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFAM4kNhVcNCxZ5ID8RAm3JAJ0TH1mvG1cnYrosKlbRg47AXIsHVgCfV3iE
sRYSOdqn472Nr1Yi/Fak7Mw=
=zlNJ
-----END PGP SIGNATURE-----
------------------------------
Date: 18 Feb 2004 18:01:25 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: how to cut a text file in perl
Message-Id: <u965e4gtca.fsf@wcl-l.bham.ac.uk>
jcharth@hotmail.com (Joseph) writes:
> hi i have a log file that it is increasing to big, how can i keep this
> file of
> a certain size, in other words, how can i make sure that the file is
> only 200 lines long and delete the first lines if longer. i think it
> would be easier to write this in a shell script. but i have no idea
> in perl. can anyone tell me how to print the last 200 lines of a file
> and overwrite the ssame file.
Deja vu anyone?
I'm curious: what keywords did you try in your Usenet search engine
before you concluded this has not already been covered?
I tried:
http://groups.google.com/groups?q=%22log+file%22+group:comp.lang.perl.*
The second hit I got was:
http://groups.google.com/groups?threadm=101eglo7mktda52%40corp.supernews.com
Where, about 3 weeks ago, essentially the same question was asked.
Here's what Uri said:
you have an interesting problem. the trouble is that your log
generator/server is still writing to the file at the seek point it
knows about. so it may leave a major gap in the file if you delete the
earlier chunk. or your server could be reopening the log file each
time which solves the first problem but you then have a race condition
regarding the removal of the early entries. but you could then copy
the older entries to a new file and rename it to the old file which is
atomic. this only works if the server reopens the file. many servers
have a way to trigger them to rotate a log file i.e. close the current
one, rename it (with some date or cycle suffix) and open a new empty
log file.
so it all comes down to how the server is managing and writing to the
log file. we would need more info on that before a proper solution can
be discussed.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 18 Feb 2004 16:45:28 -0000
From: "Hello" <sg@g2group.co.uk>
Subject: Image::magick error
Message-Id: <4033925c$0$123$7b0f0fd3@mistral.news.newnet.co.uk>
Hi,
I have just setup imagemagick to work with my Movable Type blog. It
installed ok and I set it up etc, but now I am getting errors on the web
server machine. The machine is a Windows XP Pro workstation, with IIS as the
web server. The perl version is ActivePerl 5.8.3 build 809 and the
ImageMagick version is 5.5.7 Stable.
The error that I get in the event log of that machine says;
Event Type: Error
Event Source: Application Error
Event Category: (100)
Event ID: 1000
Date: 18/02/2004
Time: 16:36:22
User: N/A
Computer: OLLY
Description:
Faulting application perl.exe, version 5.8.3.809, faulting module
Magick.dll, version 0.0.0.0, fault address 0x000023b0.
The visitor to the site gets an error saying;
CGI Error
The specified CGI application misbehaved by not returning a complete set of
HTTP headers. The headers it did return are:
Does anyone have any ideas why this might be happening ?
Olly
--
________________________________________________
ADSSupport.net
http://www.adssupport.net
Dedicated free Active Directory ServicesT support
email: oliver.marshall@nospam@adssupport.net
------------------------------
Date: Wed, 18 Feb 2004 18:35:42 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Image::magick error
Message-Id: <c10b9u$a0u$3@wisteria.csv.warwick.ac.uk>
"Hello" <sg@g2group.co.uk> wrote:
> I have just setup imagemagick to work with my Movable Type blog. It
> installed ok and I set it up etc, but now I am getting errors on the web
> server machine. The machine is a Windows XP Pro workstation, with IIS as the
> web server. The perl version is ActivePerl 5.8.3 build 809 and the
> ImageMagick version is 5.5.7 Stable.
>
> The error that I get in the event log of that machine says;
>
> Event Type: Error
> Event Source: Application Error
> Event Category: (100)
> Event ID: 1000
> Date: 18/02/2004
> Time: 16:36:22
> User: N/A
> Computer: OLLY
> Description:
> Faulting application perl.exe, version 5.8.3.809, faulting module
> Magick.dll, version 0.0.0.0, fault address 0x000023b0.
Hmmm, without knowing much about IIS, this looks to me like a segfault.
I would *strongly* recommend not using Image::Magick, and using GD or
something else instead: from what I've seen of IMagick's source, it's
amazing it ever runs without segfaulting.
Ben
--
Although few may originate a policy, we are all able to judge it.
- Pericles of Athens, c.430 B.C.
ben@morrow.me.uk
------------------------------
Date: Wed, 18 Feb 2004 07:44:46 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Listbox and passing entries
Message-Id: <e9101c.kq9.ln@goaway.wombat.san-francisco.ca.us>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On 2004-02-18, Old School <a@b.com> wrote:
> Unfortunately, the server I am using doesn't have CGI, so I am using
> cgi-lib.pl as a substitute.
You should instead install your own CGI.pm.
perldoc -q module library
[TOFU snipped]
- --keith
- --
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFAM4hphVcNCxZ5ID8RArQDAJ0ZNd+1qh3sA8+PYR6cM5hr8Qj5eACggt8X
Nup4baDWLo2MB7yLYvnaCJU=
=fOqz
-----END PGP SIGNATURE-----
------------------------------
Date: Wed, 18 Feb 2004 18:50:33 GMT
From: "Old School" <a@b.com>
Subject: Re: Listbox and passing entries
Message-Id: <ZtOYb.19369$M76.3455@fe2.texas.rr.com>
I'm at the mercy of my hosting company, and cgi-lib.pl should be able to do
the same as CGI.pm in this regard with lower overhead. But it is just
returning the last item in the multiple selections.
example:
<select multiple size="3" name=LCHAR> (no value specified)
<option>1</option>(selected)
<option>2</option>
<option>3</option>(selected)
@lchar = &SplitParam($form{'LCHAR'});
foreach $lchar (@lchar){
print "<p>$lchar</p>";
}
1 and 3 selected; only 3 returned.
"Keith Keller" <kkeller-usenet@wombat.san-francisco.ca.us> wrote in message
news:e9101c.kq9.ln@goaway.wombat.san-francisco.ca.us...
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> On 2004-02-18, Old School <a@b.com> wrote:
>
> > Unfortunately, the server I am using doesn't have CGI, so I am using
> > cgi-lib.pl as a substitute.
>
> You should instead install your own CGI.pm.
>
> perldoc -q module library
>
> [TOFU snipped]
>
> - --keith
>
> - --
> kkeller-usenet@wombat.san-francisco.ca.us
> (try just my userid to email me)
> AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
>
> -----BEGIN xxx SIGNATURE-----
> Version: GnuPG v1.2.3 (GNU/Linux)
>
> iD8DBQFAM4hphVcNCxZ5ID8RArQDAJ0ZNd+1qh3sA8+PYR6cM5hr8Qj5eACggt8X
> Nup4baDWLo2MB7yLYvnaCJU=
> =fOqz
> -----END PGP SIGNATURE-----
------------------------------
Date: Wed, 18 Feb 2004 10:21:21 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: mac ftp
Message-Id: <180220041021211984%jgibson@mail.arc.nasa.gov>
In article <402E8356.DB79BE29@asgweb.net>, Todd Anderson
<todd@asgweb.net> wrote:
> Hello,
> Does anyone know of a mac ftp program that will allow me to login and
> upload my perl scripts as nobody?
> Thanks in advance for your help.
>
While this is a bit off-topic for clpm, I will offer the following
advice: if you are using Mac OS X, you can use the Terminal application
to get a command-line prompt and "ftp" to start the built-in ftp
client. If you prefer a GUI application, try the Apple website for free
downloads of shareware and demos:
http://www.apple.com/downloads/macosx/internet_utilities/
Personally, I use the commercial products Vicomsoft FTP client (
http://www.ftpclient.com/ )
and Captain FTP ( http://captainftp.xdsnet.de/ ) and like them both. In
the past, I have also used the Panic Transmit client (
http://www.panic.com/transmit/ ). If you are still using Mac OS 9,
these commercial products probably still have versions for that OS.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V10 Issue 6153
***************************************