[28998] in Perl-Users-Digest
Perl-Users Digest, Issue: 242 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 20 14:11:06 2007
Date: Tue, 20 Mar 2007 11:09:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 20 Mar 2007 Volume: 11 Number: 242
Today's topics:
Re: "Casting" a split into an array <wahab-mail@gmx.de>
Re: checking for filehandle <ben@morrow.me.uk>
dealing with modified csv data format <junk@yahoo.com>
Re: dealing with modified csv data format <mritty@gmail.com>
Re: dealing with modified csv data format <junk@yahoo.com>
Re: FAQ 8.4 How do I print something out in color? <brian.d.foy@gmail.com>
Re: FAQ 8.4 How do I print something out in color? <brian.d.foy@gmail.com>
how to get next day <not_valid2@yahoo.com>
Re: how to get next day <jurgenex@hotmail.com>
Re: how to get next day usenet@DavidFilmer.com
Re: I dotn understand this error <hackeras@gmail.com>
Re: Net::Telnet Error handling/trapping <nospam@example.com>
Re: Net::Telnet Error handling/trapping <uri@stemsystems.com>
Re: perl: adding lines and replacing stings <mritty@gmail.com>
Re: perl: adding lines and replacing stings <kalyan.manchikanti@gmail.com>
Re: perl: adding lines and replacing stings <mritty@gmail.com>
Re: perl: adding lines and replacing stings <samdaniels@gmail.com>
Re: perl: adding lines and replacing stings <ben@morrow.me.uk>
Re: perl: adding lines and replacing stings <uri@stemsystems.com>
Re: Perl:CGI - Creating a Please wait message <wjharrisiii@optonline.net>
Re: Server/Clients system <tzz@lifelogs.com>
Re: Server/Clients system <deadpickle@gmail.com>
Re: Server/Clients system <no@email.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 20 Mar 2007 16:31:07 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: "Casting" a split into an array
Message-Id: <etp37d$ds6$1@mlucom4.urz.uni-halle.de>
Fabrice Baro wrote:
> I'm planning to shuffle an index and pick the desired number of
> letters.
>
> Original:
> 0 1 2 3 4 5 <- index
> L G R D T I <- letters
>
> Shuffle:
> 4 2 5 1 0 3
> T R I G
> ^
> Pick until here
>
> Does anyone see a better way ?
I tried it but could not
come up with a very clever solution ;-)
Thats what I have:
use strict;
use warnings;
use List::Util qw'shuffle';
sub CODES { my $z=1; join '', map substr($_[0],$_,1), grep $z*=$_,@_[1..$#_] }
my @index = qw'0 1 2 3 4 5';
my $string ='LGRDTI';
my $sh = CODES $string, shuffle @index;
print $sh;
Regards
M.
------------------------------
Date: Tue, 20 Mar 2007 16:13:30 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: checking for filehandle
Message-Id: <aqd5d4-2vb.ln1@osiris.mauzo.dyndns.org>
Quoth anno4000@radom.zrz.tu-berlin.de:
> Yakov <iler.ml@gmail.com> wrote in comp.lang.perl.misc:
> > On Mar 19, 7:23 am, anno4...@radom.zrz.tu-berlin.de wrote:
> > > Yakov <iler...@gmail.com> wrote in comp.lang.perl.misc:
> > >
> > > > Let's say I want to check whether $fh is a filehandle. Take 1
> > > > is to: defined(fileno($fh)). Perfect solution ? No. When $fh is a
> > > > tied-filehandle, $fh may not have real filedescriptor behind it
> > > > ( for example, it sends output to the shared memory ).
> > >
> > > > How do I check for $fh being a filehandle, the check would work
> > > > even for tied filehandles that do not have real filedescriptor ?
> > >
> > > In general it is hard to say for sure what a tied variable will respond
> > > to. You can use tied() to access the underlying object and make
> > > plausibility tests:
> > >
> > > my $is_fh = tied( $h) && tied( $h)->isa( 'File::Handle');
> > >
> > > or
> > >
> > > my $is_fh = tied( $h) && tied( $h)->can( 'READ');
> > >
> > > or similar. Both can go wrong, but will give the correct answer in most
> > > cases.
> >
> > Ok thanks. This seems to be the check:
> >
> > defined(fileno($fh)) || (tied( $fh) && tied($fh)-
> > >can( 'TIEHANDLE' ))
> >
> > Looks ok ?
>
> Yes. In fact, testing for "TIEHANDLE" should be pretty much watertight.
Not at all. Consider:
#!/usr/bin/perl -l
use Tie::Handle;
use Tie::Scalar;
use Scalar::Util qw/openhandle/;
use IO::Scalar;
{
package Foo;
use base qw/Tie::StdScalar Tie::StdHandle/;
}
sub is_a_handle {
return 1 if defined fileno $_[0];
return tied($_[0]) and tied($_[0])->can('TIEHANDLE');
}
my $x = \do { local *F };
tie *$x, 'Tie::StdHandle';
tie my $y, 'Foo';
my $tmp;
my $z = IO::Scalar->new(\$tmp);
print '$x is ', openhandle($x) ? 'a handle' : 'not a handle';
print '$y is ', openhandle($y) ? 'a handle' : 'not a handle';
print '$y will appear to be ',
is_a_handle($y) ? 'a handle' : 'not a handle';
print '$z is ', openhandle($z) ? 'a handle' : 'not a handle';
print '$z will appear to be ',
is_a_handle($z) ? 'a handle' : 'not a handle';
__END__
~/src/perl% perl tiehandle
$x is a handle
$y is not a handle
$y will appear to be a handle
$z is a handle
Can't locate object method "FILENO" via package "IO::Scalar" at
tiehandle line 15.
The correct answer is Scalar::Util::openhandle.
Ben
--
#!/bin/sh
quine="echo 'eval \$quine' >> \$0; echo quined"
eval $quine
# [ben@morrow.me.uk]
------------------------------
Date: Tue, 20 Mar 2007 12:06:08 -0400
From: nun <junk@yahoo.com>
Subject: dealing with modified csv data format
Message-Id: <veadnVB5SPzwm53bnZ2dnUVZ_o6gnZ2d@megapath.net>
I wrote a script which parses csv data files which were provided to me
in the following format.
WL,WA6B,SCRAPE,N,5.99,6.85,8.56,4.98
WL,W30,RULE6"",N,7.90,47.90,6.05,3.15
Note the comma field separator and that some fields have double quotes
in the data.
My script read this data in as follows and all was well:
###############################
# reading data in from file
my (@AoA);
while ( <> ) {
chomp;
push @AoA, [ split /,/ ];
}
################################
Now suddenly I'm being given the data in a slightly different format,
still comma separated but now all fields are enclosed by double quotes,
even those which have double quotes in the data, such as:
"WL","WA6B","SCRAPE","N","5.99","6.85","8.56","4.98"
"WL","W30","RULE6""","N","7.90","47.90","6.05","3.15"
Is there an easy way I can modify my code to deal with this new format,
or must I start over with something like TEXT::CSV instead of split? I'm
no perl guru and am hoping for an easy cure :)
DB
------------------------------
Date: 20 Mar 2007 09:58:06 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: dealing with modified csv data format
Message-Id: <1174409886.537126.319450@p15g2000hsd.googlegroups.com>
On Mar 20, 12:06 pm, nun <j...@yahoo.com> wrote:
> I wrote a script which parses csv data files which were provided to me
> in the following format.
>
> WL,WA6B,SCRAPE,N,5.99,6.85,8.56,4.98
> WL,W30,RULE6"",N,7.90,47.90,6.05,3.15
>
> Note the comma field separator and that some fields have double quotes
> in the data.
>
> My script read this data in as follows and all was well:
>
> ###############################
> # reading data in from file
> my (@AoA);
> while ( <> ) {
> chomp;
> push @AoA, [ split /,/ ];
> }
> ################################
>
> Now suddenly I'm being given the data in a slightly different format,
> still comma separated but now all fields are enclosed by double quotes,
> even those which have double quotes in the data, such as:
>
> "WL","WA6B","SCRAPE","N","5.99","6.85","8.56","4.98"
> "WL","W30","RULE6""","N","7.90","47.90","6.05","3.15"
>
> Is there an easy way I can modify my code to deal with this new format,
> or must I start over with something like TEXT::CSV instead of split? I'm
> no perl guru and am hoping for an easy cure :)
Why not just keep it the way it is, but then remove all the beginning/
ending quotes from each field after you've split?
push @AoA, [ split /,/ ];
s/^"// and s/"$// for @{$AoA[-1]};
Paul Lalli
------------------------------
Date: Tue, 20 Mar 2007 13:48:52 -0400
From: nun <junk@yahoo.com>
Subject: Re: dealing with modified csv data format
Message-Id: <WqqdnSjsuMMcg53bnZ2dnUVZ_vrinZ2d@megapath.net>
Paul Lalli wrote:
> On Mar 20, 12:06 pm, nun <j...@yahoo.com> wrote:
>> I wrote a script which parses csv data files which were provided to me
>> in the following format.
>>
>> WL,WA6B,SCRAPE,N,5.99,6.85,8.56,4.98
>> WL,W30,RULE6"",N,7.90,47.90,6.05,3.15
>>
>> Note the comma field separator and that some fields have double quotes
>> in the data.
>>
>> My script read this data in as follows and all was well:
>>
>> ###############################
>> # reading data in from file
>> my (@AoA);
>> while ( <> ) {
>> chomp;
>> push @AoA, [ split /,/ ];
>> }
>> ################################
>>
>> Now suddenly I'm being given the data in a slightly different format,
>> still comma separated but now all fields are enclosed by double quotes,
>> even those which have double quotes in the data, such as:
>>
>> "WL","WA6B","SCRAPE","N","5.99","6.85","8.56","4.98"
>> "WL","W30","RULE6""","N","7.90","47.90","6.05","3.15"
>>
>> Is there an easy way I can modify my code to deal with this new format,
>> or must I start over with something like TEXT::CSV instead of split? I'm
>> no perl guru and am hoping for an easy cure :)
>
> Why not just keep it the way it is, but then remove all the beginning/
> ending quotes from each field after you've split?
>
> push @AoA, [ split /,/ ];
> s/^"// and s/"$// for @{$AoA[-1]};
>
> Paul Lalli
>
>
That works, and fits the bill as easy - thanks!
DB
------------------------------
Date: Tue, 20 Mar 2007 11:09:01 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 8.4 How do I print something out in color?
Message-Id: <200320071109017211%brian.d.foy@gmail.com>
In article <x7k5xcpo47.fsf@mail.sysarch.com>, Uri Guttman
<uri@stemsystems.com> wrote:
> >>>>> "j" == joepeck02 <joepeck02@gmail.com> writes:
>
> j> This was awesome!!! Keep submitting the tips, I am reading through
> j> them and hopefully I will make it a daily routine. This tip is really
> j> really nice!
>
> you haven't been here long. the perl faq has been posted regularly here
> for several years.
Someone posts postive and righteous feedback about something I'm doing
to help Perl, and Uri has to be a dick. I was feeling pretty good
reading the first message, and now that's gone.
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Tue, 20 Mar 2007 11:10:20 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 8.4 How do I print something out in color?
Message-Id: <200320071110201952%brian.d.foy@gmail.com>
In article <1174361432.719381.288650@n59g2000hsh.googlegroups.com>,
<joepeck02@gmail.com> wrote:
> This was awesome!!! Keep submitting the tips, I am reading through
> them and hopefully I will make it a daily routine. This tip is really
> really nice!
Thanks, I'll keep posting them.
You don't have to wait for me though. These come with Perl as the
perlfaq docs, and you can also see them at http://faq.perl.org/.
:)
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Tue, 20 Mar 2007 11:56:38 -0500
From: "Bob" <not_valid2@yahoo.com>
Subject: how to get next day
Message-Id: <46001246$0$274$8046368a@newsreader.iphouse.net>
Trying to calculate next date after user enters a date ?
can this be done with strftime ?
if user enters 1-Mar-2007, want to return 2-Mar-2007.
if user enters 5-Mar-2007, want to return 6-Mar-2007.
**************start of code ************************
use strict;
use warnings;
use POSIX 'strftime';
my $date1, date2;
print ("\n Enter the start date ex: (1-Mar-2006): ");
chomp($date1 = <STDIN>);
# calculate next day here
print ("You have entered a date of $date1 and the next day is: $date2 \n");
************** end of code ************************
------------------------------
Date: Tue, 20 Mar 2007 17:16:53 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: how to get next day
Message-Id: <9GULh.8019$FS5.4363@trndny09>
Bob wrote:
> Trying to calculate next date after user enters a date ?
One way: You could take the answer to FAQ
"How do I find yesterday's date?"
and adapt it to your slightly different needs.
jue
------------------------------
Date: 20 Mar 2007 10:17:03 -0700
From: usenet@DavidFilmer.com
Subject: Re: how to get next day
Message-Id: <1174411023.908877.213200@e65g2000hsc.googlegroups.com>
On Mar 20, 9:56 am, "Bob" <not_val...@yahoo.com> wrote:
> Trying to calculate next date after user enters a date ?
> can this be done with strftime ?
Probably. But I would use the DateCalc method of Date::Manip (and use
UnixDate to format it - even to format it to this d-Mmm-YYYY format,
which is awful, IMHO):
#!/usr/bin/perl
use strict; use warnings;
use Date::Manip;
my $date = '1-Mar-2006';
my $next_day = UnixDate(DateCalc( $date, '+ 1 day'), '%e-%b-%Y');
print "The day after $date is $next_day\n";
__END__
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: 20 Mar 2007 10:57:27 -0700
From: "=?utf-8?B?zp3Or866zr/Pgg==?=" <hackeras@gmail.com>
Subject: Re: I dotn understand this error
Message-Id: <1174413447.540281.293880@d57g2000hsg.googlegroups.com>
Michele Dondi wrote:
> On 20 Mar 2007 06:34:02 -0700, "?????" <hackeras@gmail.com> wrote:
>
> >> Do realise that a value of NOTHING is still SOMETHING that can be used
> >> but an undefined variable is the value of NOTHING that can't be
> >> used. :-P
> >
> >I still try to understand this one though! :-)
>
> Briefly, the null string, '' or "" is a false value, but is a well
> *defined* thing. In fact if you give it to the defined() function, it
> will return a true value. OTOH Perl admits a special undefined value
> which is often simply called 'undef' because it's the return value of
> the undef() function. Do not confuse that with the 'undef' *string*
> which comprises five charachters. It's the value that variables not
> yet initialized have, or that have been explicitly undef()ined or
> assigned an/the undef value.
Thank you!
------------------------------
Date: Tue, 20 Mar 2007 09:11:38 -0700
From: "Chris G." <nospam@example.com>
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <460007be$0$97266$892e7fe2@authen.yellow.readfreenews.net>
I appreciate your concern over my posting habits, but I prefer
top-posting and that's my client's default setting. That setting
controls both email and newsgroup replies, so changing it isn't really
an option. Sorry.
Regards,
Chris
Mumia W. (NOSPAM) wrote:
> Please bottom-post your replies, like I am doing in this message, and
> please read the posting guidelines for this newsgroup:
>
> http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
>
>
------------------------------
Date: Tue, 20 Mar 2007 12:22:19 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Net::Telnet Error handling/trapping
Message-Id: <x78xdromno.fsf@mail.sysarch.com>
>>>>> "CG" == Chris G <nospam@example.com> writes:
CG> I appreciate your concern over my posting habits, but I prefer
CG> top-posting and that's my client's default setting. That setting
CG> controls both email and newsgroup replies, so changing it isn't really
CG> an option. Sorry.
and you will lose many of the regulars here who will killfile you. and
there is NO default setting called top posting. it is just where the
editor leaves the cursor after you quote a post. is it so hard for you
to move the cursor down? do you have RSI? are you brain dead? do you
care about what others think? or the extra work you make others do? or
breaking longstanding guidelines in the group? did you learn anything in
kindergarten?
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 20 Mar 2007 08:19:34 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: perl: adding lines and replacing stings
Message-Id: <1174403974.357087.244440@e65g2000hsc.googlegroups.com>
On Mar 20, 11:05 am, "erobinson32" <samdani...@gmail.com> wrote:
> I would like to do three things in a single Perl script:
> 1. Add the text "FirstLine" to the very first line of a sample file.
> 2. Add the test "LastLine" to the very last line of a sample file.
> 3. Replace all of the instances of 'California' to 'Nevada' in a file.
>
> I've just been running a few commands to accomplish this, but would
> like to simplify the process:
>
> perl -pi -e 's/California/Nevada/g' testfile
> sed '1i\
> FirstLine' testfile > temp_file
> mv temp_file testfile
> sed '$a\
> LastLine' testfile > temp_file
> mv temp_file testfile
>
> Original File:
> test1 - California
> test2 - Oregon
> test3 - Texas
>
> Updated File:
> FirstLine
> test1 - Nevada
> test2 - Oregon
> test3 - Texas
> LastLine
>
> Is this possible? If not, is there a more automatic way of doing
> this? updating my .bashrc?
This is a Perl "one-liner", though in this case, that's rather a
misnomer...
$ cat sample.txt
test1 - California
test2 - Oregon
test3 - Texas
$ perl -pi -e'
$_ = "First Line\n$_" if $. == 1;
s/California/Nevada/;
$_ .= "Last Line\n" if eof;
' sample.txt
$ cat sample.txt
First Line
test1 - Nevada
test2 - Oregon
test3 - Texas
Last Line
Read more about the various command line options in
perldoc perlrun
And see also:
perldoc perlvar (for $.)
perldoc -f eof
Hope this helps,
Paul Lalli
------------------------------
Date: 20 Mar 2007 08:24:52 -0700
From: "Kalyan Manchikanti" <kalyan.manchikanti@gmail.com>
Subject: Re: perl: adding lines and replacing stings
Message-Id: <1174404292.858216.138040@y66g2000hsf.googlegroups.com>
On Mar 20, 10:05 am, "erobinson32" <samdani...@gmail.com> wrote:
> I would like to do three things in a single Perl script:
> 1. Add the text "FirstLine" to the very first line of a sample file.
> 2. Add the test "LastLine" to the very last line of a sample file.
> 3. Replace all of the instances of 'California' to 'Nevada' in a file.
>
> I've just been running a few commands to accomplish this, but would
> like to simplify the process:
>
> perl -pi -e 's/California/Nevada/g' testfile
> sed '1i\
> FirstLine' testfile > temp_file
> mv temp_file testfile
> sed '$a\
> LastLine' testfile > temp_file
> mv temp_file testfile
>
> Original File:
> test1 - California
> test2 - Oregon
> test3 - Texas
>
> Updated File:
> FirstLine
> test1 - Nevada
> test2 - Oregon
> test3 - Texas
> LastLine
>
> Is this possible? If not, is there a more automatic way of doing
> this? updating my .bashrc?
perldoc -f unshift ( to add a first line to your existing file)..
perldoc -f push ( to add a last line to your existing file)..
perldoc -f tr, perldoc -f substr and ofcourse s/ ..are just three of
the many ways you can achieve string substitution..
------------------------------
Date: 20 Mar 2007 08:34:32 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: perl: adding lines and replacing stings
Message-Id: <1174404872.503717.168150@y66g2000hsf.googlegroups.com>
On Mar 20, 11:24 am, "Kalyan Manchikanti"
<kalyan.manchika...@gmail.com> wrote:
> On Mar 20, 10:05 am, "erobinson32" <samdani...@gmail.com> wrote:
> > 1. Add the text "FirstLine" to the very first line of a
> > sample file.
> > 2. Add the test "LastLine" to the very last line of a sample
> > file.
> perldoc -f unshift ( to add a first line to your existing file)..
> perldoc -f push ( to add a last line to your existing file)..
Gah. You are suggesting the OP read the entire file into memory,
modify the array, and then print the entire array back to the file?
Please don't do this. Ever.
Paul Lalli
------------------------------
Date: 20 Mar 2007 08:38:35 -0700
From: "erobinson32" <samdaniels@gmail.com>
Subject: Re: perl: adding lines and replacing stings
Message-Id: <1174405115.005815.255000@d57g2000hsg.googlegroups.com>
On Mar 20, 11:19 am, "Paul Lalli" <mri...@gmail.com> wrote:
> On Mar 20, 11:05 am, "erobinson32" <samdani...@gmail.com> wrote:
>
>
>
> > I would like to do three things in a single Perl script:
> > 1. Add the text "FirstLine" to the very first line of a sample file.
> > 2. Add the test "LastLine" to the very last line of a sample file.
> > 3. Replace all of the instances of 'California' to 'Nevada' in a file.
>
> > I've just been running a few commands to accomplish this, but would
> > like to simplify the process:
>
> > perl -pi -e 's/California/Nevada/g' testfile
> > sed '1i\
> > FirstLine' testfile > temp_file
> > mv temp_file testfile
> > sed '$a\
> > LastLine' testfile > temp_file
> > mv temp_file testfile
>
> > Original File:
> > test1 - California
> > test2 - Oregon
> > test3 - Texas
>
> > Updated File:
> > FirstLine
> > test1 - Nevada
> > test2 - Oregon
> > test3 - Texas
> > LastLine
>
> > Is this possible? If not, is there a more automatic way of doing
> > this? updating my .bashrc?
>
> This is a Perl "one-liner", though in this case, that's rather a
> misnomer...
>
> $ cat sample.txt
> test1 - California
> test2 - Oregon
> test3 - Texas
>
> $ perl -pi -e'
> $_ = "First Line\n$_" if $. == 1;
> s/California/Nevada/;
> $_ .= "Last Line\n" if eof;
> ' sample.txt
>
> $ cat sample.txt
> First Line
> test1 - Nevada
> test2 - Oregon
> test3 - Texas
> Last Line
>
> Read more about the various command line options in
> perldoc perlrun
> And see also:
> perldoc perlvar (for $.)
> perldoc -f eof
>
> Hope this helps,
> Paul Lalli
Thanks Paul, that worked great!
------------------------------
Date: Tue, 20 Mar 2007 16:29:00 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: perl: adding lines and replacing stings
Message-Id: <cne5d4-2vb.ln1@osiris.mauzo.dyndns.org>
Quoth "erobinson32" <samdaniels@gmail.com>:
>
> I would like to do three things in a single Perl script:
> 1. Add the text "FirstLine" to the very first line of a sample file.
> 2. Add the test "LastLine" to the very last line of a sample file.
> 3. Replace all of the instances of 'California' to 'Nevada' in a file.
>
> I've just been running a few commands to accomplish this, but would
> like to simplify the process:
>
> perl -pi -e 's/California/Nevada/g' testfile
> sed '1i\
> FirstLine' testfile > temp_file
> mv temp_file testfile
> sed '$a\
> LastLine' testfile > temp_file
> mv temp_file testfile
You're nearly there :)
perl -pi -le'
BEGIN { print "FirstLine" }
s/California/Nevada/g;
END { print "LastLine" }'
Ben
--
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
ben@morrow.me.uk
------------------------------
Date: Tue, 20 Mar 2007 12:20:00 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: perl: adding lines and replacing stings
Message-Id: <x7d533omrj.fsf@mail.sysarch.com>
>>>>> "PL" == Paul Lalli <mritty@gmail.com> writes:
>> perldoc -f push ( to add a last line to your existing file)..
PL> Gah. You are suggesting the OP read the entire file into memory,
PL> modify the array, and then print the entire array back to the file?
PL> Please don't do this. Ever.
why not? if the file is small enough (and small is pretty big by today's
ram standards) it is simpler and faster to slurp in many cases. this
could be done with:
use File::Slurp ;
my $text = read_file( 'file' ) ;
$text =~ s/Nevada/California/g ;
write_file( 'file', "FirstLine\n", $text, "LastLine\n" ) ;
and when the edit_file feature is added it would be something like:
edit_file( 'file', sub{ s/Nevada/California/g ;
$_ = "FirstLine\n${_}LastLine\n" } ) ;
i totally get line by line processing but the bias against slurping
small files is silly IMO. with stdio or filesystem buffer sizes like 64k
now, you don't save any real ram with line by line and slurping usually
will be faster.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 20 Mar 2007 10:18:09 -0700
From: "Ice Man" <wjharrisiii@optonline.net>
Subject: Re: Perl:CGI - Creating a Please wait message
Message-Id: <1174411089.711961.253720@n59g2000hsh.googlegroups.com>
On Feb 17, 2:21 pm, "Marco Neumann" <krotow...@yahoo.com> wrote:
> > I hope it works for you.
>
> Ups just noticed: Insert this into the head of your temporary output file:
>
> <head>
> <meta HTTP-EQUIV="refresh" CONTENT="30">
> <meta http-equiv="Pragma" content="no-cache">
> </head>
>
> This will make it reload every 30 seconds until the child process outputs
> the final result file.
>
> Cheers,
> Marco.
Actually This helped out a lot. I got the following link from another
group
which is actually a great example! Appreciate your response and sorry
for
my late reply:
http://www.stonehenge.com/merlyn/WebTechniques/col20.html
-Bill
------------------------------
Date: Tue, 20 Mar 2007 11:23:52 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Server/Clients system
Message-Id: <g691wjk6irb.fsf@dhcp-65-162.kendall.corp.akamai.com>
On 20 Mar 2007 07:04:30 -0700 "deadpickle" <deadpickle@gmail.com> wrote:
d> First of all I havent wrote any code for this yet, I'm still in the
d> brainstorming section. What I want to do is have a server that resides
d> on a networked computer somewhere. This server will recieve files from
d> 2 clients. Then these 2 clients will ask the server for another file
d> and the server will send it. So in summary I have 2 Clients that can
d> send and recieve files and a Server that can recieve and send files.
d> Hope that makes sense. I am not sure on how to do this, or how to get
d> started, anyone got any ideas?
Well, you could implement this with FTP or HTTP (HTTP has a "PUT"
command), reimplementing as much of the protocol as you desire. Are
you trying to implement something new as a fun project, or is this
real work? In the real world I'd avoid writing new protocols when so
many good ones exist already (implemented in C, bug-free, etc.).
Depending on your server and client, and your particular needs, you
could go with
FTP
HTTP
rsync
WebDAV
SCP/SFTP
BitTorrent
NFS/AFS/Samba/etc. networked filesystems
plus many others I can't think of right now. Note these are sorted by
length, not by how much I like them :)
Ted
------------------------------
Date: 20 Mar 2007 10:20:50 -0700
From: "deadpickle" <deadpickle@gmail.com>
Subject: Re: Server/Clients system
Message-Id: <1174411250.275433.44030@p15g2000hsd.googlegroups.com>
On Mar 20, 9:23 am, Ted Zlatanov <t...@lifelogs.com> wrote:
> On 20 Mar 2007 07:04:30 -0700 "deadpickle" <deadpic...@gmail.com> wrote:
>
> d> First of all I havent wrote any code for this yet, I'm still in the
> d> brainstorming section. What I want to do is have a server that resides
> d> on a networked computer somewhere. This server will recieve files from
> d> 2 clients. Then these 2 clients will ask the server for another file
> d> and the server will send it. So in summary I have 2 Clients that can
> d> send and recieve files and a Server that can recieve and send files.
> d> Hope that makes sense. I am not sure on how to do this, or how to get
> d> started, anyone got any ideas?
>
> Well, you could implement this with FTP or HTTP (HTTP has a "PUT"
> command), reimplementing as much of the protocol as you desire. Are
> you trying to implement something new as a fun project, or is this
> real work? In the real world I'd avoid writing new protocols when so
> many good ones exist already (implemented in C, bug-free, etc.).
> Depending on your server and client, and your particular needs, you
> could go with
>
> FTP
> HTTP
> rsync
> WebDAV
> SCP/SFTP
> BitTorrent
> NFS/AFS/Samba/etc. networked filesystems
>
> plus many others I can't think of right now. Note these are sorted by
> length, not by how much I like them :)
>
> Ted
This is for a undergraduate project at my university. I'm thinking
about using BitTorrent. I want this whole system to be autonomous and
to make many transfers every minute, can BitTorrent do this?
------------------------------
Date: Tue, 20 Mar 2007 17:56:07 +0000
From: Brian Wakem <no@email.com>
Subject: Re: Server/Clients system
Message-Id: <56alhnF26jcosU1@mid.individual.net>
deadpickle wrote:
> First of all I havent wrote any code for this yet, I'm still in the
> brainstorming section. What I want to do is have a server that resides
> on a networked computer somewhere. This server will recieve files from
> 2 clients. Then these 2 clients will ask the server for another file
> and the server will send it. So in summary I have 2 Clients that can
> send and recieve files and a Server that can recieve and send files.
> Hope that makes sense. I am not sure on how to do this, or how to get
> started, anyone got any ideas?
I would just use Apache as the server and write a cgi script (or mod_perl)
to deal with the files. No point re-inventing the wheel.
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
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 V11 Issue 242
**************************************