[33049] in Perl-Users-Digest
Perl-Users Digest, Issue: 4325 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 8 21:09:21 2014
Date: Mon, 8 Dec 2014 18:09:08 -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 Mon, 8 Dec 2014 Volume: 11 Number: 4325
Today's topics:
Re: Can you point me in the right direction - accessing <jblack@nospam.com>
Date procedure? <tuxedo@mailinator.com>
Re: Date procedure? <tuxedo@mailinator.com>
Re: Date procedure? <gamo@telecable.es>
Re: Date procedure? <tuxedo@mailinator.com>
Re: Date procedure? <ben.usenet@bsb.me.uk>
Re: Date procedure? <jblack@nospam.com>
Re: Date procedure? <netnews@invalid.com>
Re: Date procedure? <gamo@telecable.es>
Re: Date procedure? <tuxedo@mailinator.com>
Re: Date procedure? <gravitalsun@hotmail.foo>
Re: Date procedure? <gamo@telecable.es>
Re: Date procedure? <tuxedo@mailinator.com>
Re: Dedup script is finished and works. Critiques? <gravitalsun@hotmail.foo>
Need a Mac Script to search and print lines in all text <thecjguy1@gmail.com>
Re: Need a Mac Script to search and print lines in all <jurgenex@hotmail.com>
Re: Need a Mac Script to search and print lines in all <justin.1410@purestblue.com>
Re: Need a Mac Script to search and print lines in all <rweikusat@mobileactivedefense.com>
Re: Need a Mac Script to search and print lines in all <thecjguy1@gmail.com>
Re: Need a Mac Script to search and print lines in all <rweikusat@mobileactivedefense.com>
Re: Need a Mac Script to search and print lines in all <jurgenex@hotmail.com>
Re: Need a Mac Script to search and print lines in all <kkeller-usenet@wombat.san-francisco.ca.us>
Re: Read/write specific lines? <derykus@gmail.com>
Re: Read/write specific lines? <justin.1410@purestblue.com>
Re: Read/write specific lines? <gamo@telecable.es>
Re: Read/write specific lines? <rweikusat@mobileactivedefense.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 7 Dec 2014 22:39:22 -0600
From: John Black <jblack@nospam.com>
Subject: Re: Can you point me in the right direction - accessing a website
Message-Id: <MPG.2eeee778967f038698980a@news.eternal-september.org>
In article <Z8ydnQnwQ-vf1B7JnZ2dnUVZ8oGdnZ2d@giganews.com>, news@lawshouse.org says...
> There's a module called WWW::Mechanize::Firefox which (AIUI) allows you
> to use FF as the browser engine, but with Perl pulling its strings.
> I've not tried it, but it might do what you want.
Thanks. This looks like it *could be* EXACTLY what I need. Firefox already knows how to do
the million things that it needs to do to get into these sites so why would I re-invent the
wheel. I can just have firefox do it for me and give me the results.
Of course nothing goes smoothly and there is apparently an incompatability with
WWW::Mechanize::Firefox and cygwin. I think I hacked my way through that but its taken hours
so I may have to continue this project tomorrow.
But I am hopeful for going this route. Thanks again.
John Black
------------------------------
Date: Mon, 8 Dec 2014 15:00:45 +0100
From: Tuxedo <tuxedo@mailinator.com>
Subject: Date procedure?
Message-Id: <m64aue$5ll$1@news.albasani.net>
I have an $orig_date variable string contaning for example:
2014-12-08
I'd like to keep the original format to more easily make use of the same
data whenever some other function may require a date for processing and
comparing something else.
However, to keep everyone everywhere happy with what they see displayed,
can someone here advise me on a procedure to reorganise such formatted date
into a more humanly readable string, placing a reformatted date in for
example a new $date_en variable:
8 December 2014
Maybe there is even some convenient module that can return different local
style date conventions or languages based on the yyyy-mm-dd format to print
for example:
8 décembre 2014
8 diciembre 2014
12/08/2014
08/12/2014
etc.
Many thanks for any tips!
Tuxedo
------------------------------
Date: Mon, 8 Dec 2014 18:37:20 +0100
From: Tuxedo <tuxedo@mailinator.com>
Subject: Re: Date procedure?
Message-Id: <m64nkh$up8$1@news.albasani.net>
Tuxedo wrote:
[...]
> Maybe there is even some convenient module that can return different local
> style date conventions or languages based on the yyyy-mm-dd format to
> print for example:
I guess Date-Manip is the main date module in existence, although perhaps
it's a bit heavyweight for performing only a small purpose conversion, such
as from "2014-12-08" to "8 December 2014" format?
Tuxedo
------------------------------
Date: Mon, 08 Dec 2014 20:42:29 +0100
From: gamo <gamo@telecable.es>
Subject: Re: Date procedure?
Message-Id: <m64uv1$vul$1@speranza.aioe.org>
El 08/12/14 a las 18:37, Tuxedo escribió:
> Tuxedo wrote:
>
> [...]
>
>> Maybe there is even some convenient module that can return different local
>> style date conventions or languages based on the yyyy-mm-dd format to
>> print for example:
>
> I guess Date-Manip is the main date module in existence, although perhaps
> it's a bit heavyweight for performing only a small purpose conversion, such
> as from "2014-12-08" to "8 December 2014" format?
>
> Tuxedo
>
I guess is DateTime, don't know about that.
--
http://www.telecable.es/personales/gamo/
The generation of random numbers is too important to be left to chance
------------------------------
Date: Mon, 8 Dec 2014 20:55:46 +0100
From: Tuxedo <tuxedo@mailinator.com>
Subject: Re: Date procedure?
Message-Id: <m64vo4$fp6$1@news.albasani.net>
gamo wrote:
[...]
> I guess is DateTime, don't know about that.
Many thanks - I will look into the DateTime module.
So far I did not yet find a way to convert a 2014-12-08 type of date string
to a more universally human readable format such as 8 December 2014.
I did however find a way to produce nearly the needed output directly and
without the use of a module:
use strict;
use warnings;
use POSIX qw(strftime);
my $datestring = strftime "%d %B %Y", gmtime;
print "$datestring\n";
prints:
08 December 2014
As said, the above is not the exact output I was hoping for. In any case,
is the above a good way to generate a date, and if so, is it possible to
easily expand on the above method to also, 1) redefine the words in some
other language by explicity typing out the twelve months into a list, and
2) remove the leading zero from the date string whenever there is one?
Tuxedo
------------------------------
Date: Mon, 08 Dec 2014 20:47:54 +0000
From: Ben Bacarisse <ben.usenet@bsb.me.uk>
Subject: Re: Date procedure?
Message-Id: <87r3w9j2bp.fsf@bsb.me.uk>
Tuxedo <tuxedo@mailinator.com> writes:
<snip>
> I did however find a way to produce nearly the needed output directly and
> without the use of a module:
>
> use strict;
> use warnings;
> use POSIX qw(strftime);
>
> my $datestring = strftime "%d %B %Y", gmtime;
> print "$datestring\n";
>
> prints:
>
> 08 December 2014
>
> As said, the above is not the exact output I was hoping for. In any case,
> is the above a good way to generate a date, and if so, is it possible to
> easily expand on the above method to also, 1) redefine the words in some
> other language by explicity typing out the twelve months into a list, and
> 2) remove the leading zero from the date string whenever there is one?
Using %b covers number 1, provided the user has the appropriate locale
settings:
$ perl date.pl
08 December 2014
$ LC_TIME="es_ES.UTF-8" perl date.pl
08 diciembre 2014
Number 2 is best dealt with by Perl itself -- just strip a leading 0 off
the string. However, you might prefer to use %e which writes a space
instead of a leading 0. In some contexts you may not need to trim it
all.
--
Ben.
------------------------------
Date: Mon, 8 Dec 2014 16:23:33 -0600
From: John Black <jblack@nospam.com>
Subject: Re: Date procedure?
Message-Id: <MPG.2eefe0e2d88fa3bb98980b@news.eternal-september.org>
In article <m64vo4$fp6$1@news.albasani.net>, tuxedo@mailinator.com says...
> So far I did not yet find a way to convert a 2014-12-08 type of date string
> to a more universally human readable format such as 8 December 2014.
Converting dates like 2014-12-08 to 8 December 2014 is about as trivial as a program can get.
Do you know basic Perl? If not, learn that or else you will end up asking how to do every
little thing. The basics won't take very long.
John Black
------------------------------
Date: Mon, 08 Dec 2014 14:40:13 -0800
From: HASM <netnews@invalid.com>
Subject: Re: Date procedure?
Message-Id: <87y4qhzrxu.fsf@127.0.0.1>
Tuxedo <tuxedo@mailinator.com> writes:
> So far I did not yet find a way to convert a 2014-12-08 type of date
> string to a more universally human readable format such as 8 December
> 2014.
I would hope we do move towards using 2014-12-08 as the "universally human
readable format". After all, it is the ISO standard, and the only format
that sorts easily. I use it all the time in the land of the 12-08-2014
format, and have yet to have anyone blink at it.
-- HASM
------------------------------
Date: Mon, 08 Dec 2014 23:54:04 +0100
From: gamo <gamo@telecable.es>
Subject: Re: Date procedure?
Message-Id: <m65a67$678$1@speranza.aioe.org>
El 08/12/14 a las 23:40, HASM escribió:
> Tuxedo <tuxedo@mailinator.com> writes:
>
>> So far I did not yet find a way to convert a 2014-12-08 type of date
>> string to a more universally human readable format such as 8 December
>> 2014.
>
> I would hope we do move towards using 2014-12-08 as the "universally human
> readable format". After all, it is the ISO standard, and the only format
> that sorts easily. I use it all the time in the land of the 12-08-2014
> format, and have yet to have anyone blink at it.
>
> -- HASM
>
Well said!
--
http://www.telecable.es/personales/gamo/
The generation of random numbers is too important to be left to chance
------------------------------
Date: Tue, 9 Dec 2014 00:10:43 +0100
From: Tuxedo <tuxedo@mailinator.com>
Subject: Re: Date procedure?
Message-Id: <m65b5k$5j1$1@news.albasani.net>
John Black wrote:
[...]
> Converting dates like 2014-12-08 to 8 December 2014 is about as trivial as
> a program can get.
Maybe you can explain how?
> Do you know basic Perl? If not, learn that or else you will end up asking
> how to do every
> little thing. The basics won't take very long.
Yes, and there are many ways to do the same. Naturally it's easy to take
the string apart and apply some REs to each part and piece it together in
some new format but it's surely not the most efficient way. I'm having a
look into various date related modules now but didn't find or figure a
particular one to do this conversion yet, even if it's not a great idea to
use some heavyweight module for such a small task as this.
Here is sometimes where the best answers can be found.
Tuxedo
------------------------------
Date: Tue, 09 Dec 2014 01:15:38 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: Date procedure?
Message-Id: <m65bf0$10bv$1@news.ntua.gr>
On 8/12/2014 16:00, Tuxedo wrote:
> I have an $orig_date variable string contaning for example:
>
> 2014-12-08
>
use strict;
use warnings;
use feature qw/say/;;
my $orig_date = '2014-12-08';
say ReformatDay('$DD $MM $Y', $orig_date);
say ReformatDay('$D ($DDDD) $M ($MMMM) $Y', $orig_date);
say ReformatDay('$MMM/$DDD $Y', $orig_date);
# $M = 2
# $MM = 02
# $MMM = Feb
# $MMMM = February
# $D = 9
# $DD = 09
# $DDD = Sun
# $DDDD = Sunday
# $Y = 2014
#
sub ReformatDay
{
my ($Y,$M,$D) = $_[1] =~/^(\d{4})-0?(\d{1,2})-0?(\d{1,2})$/ or return undef;
my $MM = sprintf "%02d", $M;
my $MMMM = {qw/1 January 2 February 3 March 4 April 5 May 6 June 7 July
8 August 9 September 10 October 11 November 12 December/}->{$M};
my $MMM = substr $MMMM, 0, 3;
my $DD = sprintf "%02d", $D;
my $DDDD = sub {
my ($d,$m,$y)=@_;
$m < 3 && $y--;
{0,'Sunday',1,'Monday',2,'Tuesday',3,'Wednesday',4,'Thursday',5,'Friday',6,'Saturday'}->{($d
+ ((qw/0 3 2 5 0 3 5 1 4 6 2 4/)[$m-1])
+$y+(int($y/4))-(int($y/100))+(int($y/400)))%7}
}->($D,$M,$Y);
my $DDD = substr $DDDD, 0, 3;
eval "\"$_[0]\""
}
------------------------------
Date: Tue, 09 Dec 2014 00:27:24 +0100
From: gamo <gamo@telecable.es>
Subject: Re: Date procedure?
Message-Id: <m65c4s$avn$1@speranza.aioe.org>
El 09/12/14 a las 00:10, Tuxedo escribió:
> John Black wrote:
>
> [...]
>
>> Converting dates like 2014-12-08 to 8 December 2014 is about as trivial as
>> a program can get.
>
> Maybe you can explain how?
>
>> Do you know basic Perl? If not, learn that or else you will end up asking
>> how to do every
>> little thing. The basics won't take very long.
>
> Yes, and there are many ways to do the same. Naturally it's easy to take
> the string apart and apply some REs to each part and piece it together in
> some new format but it's surely not the most efficient way. I'm having a
> look into various date related modules now but didn't find or figure a
> particular one to do this conversion yet, even if it's not a great idea to
> use some heavyweight module for such a small task as this.
>
> Here is sometimes where the best answers can be found.
>
> Tuxedo
>
Don't be so afraid for efficiency. After all is Perl, and not C.
You can do:
A) $date =~ s/(\d+)\-(\d+)\-(\d+)/$3-$2-$1/;
B) my @month = qw(NULL enero febrero marzo abril mayo junio julio
agosto septiembre octubre noviembre diciembre);
and call $month[12] whatever you want.
--
http://www.telecable.es/personales/gamo/
The generation of random numbers is too important to be left to chance
------------------------------
Date: Tue, 9 Dec 2014 00:36:36 +0100
From: Tuxedo <tuxedo@mailinator.com>
Subject: Re: Date procedure?
Message-Id: <m65cm4$80e$1@news.albasani.net>
HASM wrote:
> Tuxedo <tuxedo@mailinator.com> writes:
>
> > So far I did not yet find a way to convert a 2014-12-08 type of date
> > string to a more universally human readable format such as 8 December
> > 2014.
>
> I would hope we do move towards using 2014-12-08 as the "universally human
> readable format". After all, it is the ISO standard, and the only format
> that sorts easily. I use it all the time in the land of the 12-08-2014
> format, and have yet to have anyone blink at it.
People in different cultures may still see the 2014-12-08 a bit odd and
even mean different dates in some minds, much like the British vs US
conventions. As such, it may be a good idea to spell out the month. To
store original data in the 2014-12-08 format is definitely the way, I
agree, while maybe just modifying output depending on different situations,
such as configurable end-user preferences.
Tuxedo
------------------------------
Date: Sun, 07 Dec 2014 18:17:39 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: Dedup script is finished and works. Critiques?
Message-Id: <m61uj7$c4o$1@news.ntua.gr>
your script is unacceptable. I have written at your initial thread how
you could implemented it to be 100 times faster but you replied that
"you know what you want to do"
------------------------------
Date: Sun, 7 Dec 2014 15:39:44 -0800 (PST)
From: Chris Roberts <thecjguy1@gmail.com>
Subject: Need a Mac Script to search and print lines in all text files
Message-Id: <b0ff4192-f8e9-4817-8f38-62c7ff3b9c34@googlegroups.com>
Hi,
Perhaps someone could assist?
I want to do something like
$egrep -i -r 'My string /Users/crzzy1/*.txt' ;
and have it print out something like below...
$filename.txt: "My string"
of course, my example doesn't work and seems to have trouble with the "*"
Any help would be much appreciated.
Thanks,
crzzy1
------------------------------
Date: Sun, 07 Dec 2014 17:28:48 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Need a Mac Script to search and print lines in all text files
Message-Id: <liv98a90ol0iei4fk5ebue2t66msceoj4f@4ax.com>
Chris Roberts <thecjguy1@gmail.com> wrote:
Sorry, I do not know the programming language Mac. In this NG the topic
is Perl.
>I want to do something like
>$egrep -i -r 'My string /Users/crzzy1/*.txt' ;
>
>and have it print out something like below...
>$filename.txt: "My string"
>
>of course, my example doesn't work and seems to have trouble with the "*"
>Any help would be much appreciated.
In Perl I think you would be looking for File::Find, see
perldoc File::Find
for details.
jue
------------------------------
Date: Mon, 8 Dec 2014 10:58:21 +0000
From: Justin C <justin.1410@purestblue.com>
Subject: Re: Need a Mac Script to search and print lines in all text files
Message-Id: <drcglb-g28.ln1@zem.masonsmusic.co.uk>
On 2014-12-07, Chris Roberts <thecjguy1@gmail.com> wrote:
> Hi,
> Perhaps someone could assist?
>
> I want to do something like
> $egrep -i -r 'My string /Users/crzzy1/*.txt' ;
>
> and have it print out something like below...
> $filename.txt: "My string"
>
> of course, my example doesn't work and seems to have trouble with the "*"
> Any help would be much appreciated.
>
> Thanks,
> crzzy1
Smells like homework.
What have you tried so far? Do you know about 'glob'?
Justin.
--
Justin C, by the sea.
------------------------------
Date: Mon, 08 Dec 2014 17:05:06 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Need a Mac Script to search and print lines in all text files
Message-Id: <874mt6qdh9.fsf@doppelsaurus.mobileactivedefense.com>
Chris Roberts <thecjguy1@gmail.com> writes:
F> Perhaps someone could assist?
>
> I want to do something like
> $egrep -i -r 'My string /Users/crzzy1/*.txt' ;
>
> and have it print out something like below...
> $filename.txt: "My string"
grep -i 'My string' /Users/crzzy1/*.txt
------------------------------
Date: Mon, 8 Dec 2014 13:59:26 -0800 (PST)
From: Chris Roberts <thecjguy1@gmail.com>
Subject: Re: Need a Mac Script to search and print lines in all text files
Message-Id: <6f3c0c8d-ec1f-49df-811c-191d94cc2005@googlegroups.com>
Jue, Mac defaults to using bash.
The Google search you gave just points basically to a perl-find MAN page, so not helpful and I don't see anything in there either Perl or Glob that can search both recursively and *.txt files for a string.
This is so much easier in Windows...
It is unbelievable that no one has an simple explanation for something that is so easy to do within DOS.
If I do egrep -i "jun.*5 .*info" /syslog/syslog.log
That works.
But if I want to go through all the syslog.* files and then recursively through the subdirectories.
No one has a ready made method? Really?
I thought this would be a commonly used function.
Thanks,
crzzy1
------------------------------
Date: Mon, 08 Dec 2014 22:07:21 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Need a Mac Script to search and print lines in all text files
Message-Id: <87r3w9pzhi.fsf@doppelsaurus.mobileactivedefense.com>
Chris Roberts <thecjguy1@gmail.com> writes:
> Jue, Mac defaults to using bash.
> The Google search you gave just points basically to a perl-find MAN
> page, so not helpful and I don't see anything in there either Perl or
> Glob that can search both recursively and *.txt files for a string.
>
> This is so much easier in Windows...
> It is unbelievable that no one has an simple explanation for something
> that is so easy to do within DOS.
> If I do egrep -i "jun.*5 .*info" /syslog/syslog.log
> That works.
> But if I want to go through all the syslog.* files and then
> recursively through the subdirectories.
>
> No one has a ready made method? Really?
BSD grep supports -r for recursing into subdirectories. In case the
version you have doesn't, you can always use
find . -type f | xargs grep 'a string'
BTW, you don't only seem to be committed to whine about your problem
instead of doing something about (how about checking the grep
documentation?) but you're also completely off topic here.
------------------------------
Date: Mon, 08 Dec 2014 15:11:29 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Need a Mac Script to search and print lines in all text files
Message-Id: <1bbc8apc7tbfp670noaad48dc2dh1q0tvt@4ax.com>
Chris Roberts <thecjguy1@gmail.com> wrote:
>
>Jue, Mac defaults to using bash.
I am quite familiar with bash.
I still have no idea what programming language Mac ist.
And neither of them is Perl which is the only programming language that
is on-topic in this NG.
>The Google search you gave
I never gave any Google search. I gave you the correct command to call
the perldoc document that explains how to use the Perl module
File::Find.
>just points basically to a perl-find MAN page, so not helpful
Of course it is helpful. If you don't understand it then that doesn't
mean it is not helpful. It perfectly explains how to use File::Find to
achive what you are looking for.
>and I don't see anything in there either Perl or Glob that can search both recursively and *.txt files for a string.
It is all in the wanted() function which on each file can do whatever
you want it to do.
>This is so much easier in Windows...
>It is unbelievable that no one has an simple explanation for something that is so easy to do within DOS.
You are not seriously comparing DOS and Perl, are you? That would be
like comparing a Ford Model T and a modern Ferrari.
>If I do egrep -i "jun.*5 .*info" /syslog/syslog.log
>That works.
>But if I want to go through all the syslog.* files and then recursively through the subdirectories.
That's exactly what File::Find does.
>No one has a ready made method? Really?
>I thought this would be a commonly used function.
Of course it is. In your wanted() function just check if the file name
matches *.txt and if yes then scan through the content of the file.
That is Perl Basics 101 for Beginners.
Of course there are also ready-made tools for that job, e.g. grep, but
because you are asking in a Perl NG I suppose you are looking for a Perl
solution, aren't you?
jue
------------------------------
Date: Mon, 8 Dec 2014 17:35:46 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Need a Mac Script to search and print lines in all text files
Message-Id: <i80ilbxpns.ln2@goaway.wombat.san-francisco.ca.us>
On 2014-12-08, Chris Roberts <thecjguy1@gmail.com> wrote:
>
> Jue, Mac defaults to using bash.
bash is not Perl.
> This is so much easier in Windows...
Windows is not Perl.
> It is unbelievable that no one has an simple explanation for something that is so easy to do within DOS.
DOS is not Perl.
> If I do egrep -i "jun.*5 .*info" /syslog/syslog.log
egrep is not Perl.
> No one has a ready made method? Really?
> I thought this would be a commonly used function.
The File::Find Perl module is the commonly used library a Perl
programmer would use. But it seems like you're not using Perl.
There are newsgroups for OS X where your question would be less
inappropriate.
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information
------------------------------
Date: Sun, 7 Dec 2014 12:41:43 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: Read/write specific lines?
Message-Id: <8cb5c84a-45a5-4841-b53e-6603e4b86d41@googlegroups.com>
On Friday, December 5, 2014 4:50:59 AM UTC-8, Tuxedo wrote:
> Hello,
>
> I have a file with two lines, for example:
>
> 75
> line two
>
> I would like read from and write to the first line only, something along:
>
> open(FILE, "<file") or die("Could not open to read $!");
> my $value = <FILE>; # but read only first line with the number?
> # read the second line?
>
> close(FILE);
>
> $value++; # modify the value found on the first line
>
> open(FILE, ">file") or die("could not open to write $!");
> print FILE $value;
> # write first line, as above, then copy the second unmodified line below?
>
> close(FILE);
>
> How can the first, second or any other specified line be read and thereby
> have modifications made to specific line numbers?
>
> In the above example I presume one way is to read the whole file and modify
> line one and thereafter write back the whole and partly modified file.
>
Tie::File is core and, although slow, is another possibility:
tie my @array, 'Tie::File', '/path/to/some/file';
$array[0] = ...;
untie @array;
--
Charles DeRykus
------------------------------
Date: Mon, 8 Dec 2014 13:00:00 +0000
From: Justin C <justin.1410@purestblue.com>
Subject: Re: Read/write specific lines?
Message-Id: <gvjglb-omb.ln1@zem.masonsmusic.co.uk>
On 2014-12-05, gamo <gamo@telecable.es> wrote:
>
> The simplest way: A) read one file, modify, write other file
> then, B) perldoc -f rename; perldoc -f unlink or even File::Copy
Surely the correct way is to do what the command line -i does and
copy to backup, open the backup, write a new file with the same
name as the original. You can test failure and die at every step
without risking data loss.
Justin.
--
Justin C, by the sea.
------------------------------
Date: Mon, 08 Dec 2014 14:35:50 +0100
From: gamo <gamo@telecable.es>
Subject: Re: Read/write specific lines?
Message-Id: <m649fk$86i$1@speranza.aioe.org>
El 08/12/14 a las 14:00, Justin C escribió:
> On 2014-12-05, gamo <gamo@telecable.es> wrote:
>>
>> The simplest way: A) read one file, modify, write other file
>> then, B) perldoc -f rename; perldoc -f unlink or even File::Copy
>
> Surely the correct way is to do what the command line -i does and
> copy to backup, open the backup, write a new file with the same
> name as the original. You can test failure and die at every step
> without risking data loss.
>
> Justin.
>
Then it can be well done and invoqued as perl -i.bak
-i[extension] edit <> files in place (makes backup if extension
supplied)
I suppose that if you doesn't supply the extension, no backup is
done. It needs be tested before, because by "<> files" I could
understand no file at all, as in cat file | perl script.
--
http://www.telecable.es/personales/gamo/
------------------------------
Date: Mon, 08 Dec 2014 15:07:03 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Read/write specific lines?
Message-Id: <87fvcqfaeg.fsf@doppelsaurus.mobileactivedefense.com>
Justin C <justin.1410@purestblue.com> writes:
> On 2014-12-05, gamo <gamo@telecable.es> wrote:
>> The simplest way: A) read one file, modify, write other file
>> then, B) perldoc -f rename; perldoc -f unlink or even File::Copy
>
> Surely the correct way is to do what the command line -i does and
> copy to backup, open the backup, write a new file with the same
> name as the original.
It's usually a better idea to write the data to a new file and use
rename to replace the old file afterwards as this means that 'other
software' will either see the complete new file or the complete old
file, at least on systems where rename can be used on this way.
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 4325
***************************************