[32564] in Perl-Users-Digest
Perl-Users Digest, Issue: 3830 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 2 21:09:22 2012
Date: Sun, 2 Dec 2012 18:09:06 -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 Sun, 2 Dec 2012 Volume: 11 Number: 3830
Today's topics:
Insert newline before date in yyyy-mm-dd format <kw@codebykevin.com>
Re: Insert newline before date in yyyy-mm-dd format <dave@invalid.invalid>
Re: Insert newline before date in yyyy-mm-dd format <ben@morrow.me.uk>
Re: Insert newline before date in yyyy-mm-dd format <kw@codebykevin.com>
Re: using templates effectively act Two scene 1 <cal@example.invalid>
Re: using templates effectively act Two scene 1 <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 01 Dec 2012 13:17:09 -0500
From: Kevin Walzer <kw@codebykevin.com>
Subject: Insert newline before date in yyyy-mm-dd format
Message-Id: <k9dhj6$ruq$1@dont-email.me>
I am parsing a text-delimited file that has been saved as a single line.
It's actually supposed to be a multiline file with a date in yyyy-mm-dd
format as the first field on each line. To correctly structure the data,
I'm trying to insert insert a newline character before all date fields
and and then split the file into an array on the newline char. The issue
I'm running into is that I can't get the substitution pattern right.
Here's my code:
my $date1="([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])";
my $date2="\n([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])";
$_ =~ s/$date1/$date2/g;
This pattern appears to correctly match the date field, but rather
simply inserting a newline in front of the date field's data it inserts
a newline and then a string literal that looks like this:
([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])
What I want is to replace 2012-01-01 with \n2012-01-01, and all
subsequent date fields in the file in the same fashion. Can someone
suggest a better way to do this?
Thanks,
Kevin
--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
------------------------------
Date: Sat, 1 Dec 2012 19:22:10 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Re: Insert newline before date in yyyy-mm-dd format
Message-Id: <fV45K0OBJxbE-pn2-8HN9ZuvNdtn4@localhost>
On Sat, 1 Dec 2012 18:17:09 UTC, Kevin Walzer <kw@codebykevin.com>
wrote:
> I am parsing a text-delimited file that has been saved as a single line.
> It's actually supposed to be a multiline file with a date in yyyy-mm-dd
> format as the first field on each line. To correctly structure the data,
> I'm trying to insert insert a newline character before all date fields
> and and then split the file into an array on the newline char. The issue
> I'm running into is that I can't get the substitution pattern right.
>
> Here's my code:
>
> my $date1="([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])";
> my $date2="\n([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])";
> $_ =~ s/$date1/$date2/g;
>
> This pattern appears to correctly match the date field, but rather
> simply inserting a newline in front of the date field's data it inserts
> a newline and then a string literal that looks like this:
>
> ([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])
>
> What I want is to replace 2012-01-01 with \n2012-01-01, and all
> subsequent date fields in the file in the same fashion. Can someone
> suggest a better way to do this?
It did what you told it to do :-)
Try s/(\d\d\d\d-\d\d-\d\d)/\n$1/g;
--
Regards
Dave Saville
------------------------------
Date: Sat, 1 Dec 2012 20:27:26 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Insert newline before date in yyyy-mm-dd format
Message-Id: <eq5qo9-v1s2.ln1@anubis.morrow.me.uk>
Quoth Kevin Walzer <kw@codebykevin.com>:
> I am parsing a text-delimited file that has been saved as a single line.
> It's actually supposed to be a multiline file with a date in yyyy-mm-dd
> format as the first field on each line. To correctly structure the data,
> I'm trying to insert insert a newline character before all date fields
> and and then split the file into an array on the newline char.
If you just want to split the text into an array, you don't need to
insert newlines first. Just split on a zero-width assertion:
my @lines = split /(?=[0-9]{4}-[0-9]{2}-[0-9]{2})/;
That (?=) matches the gap between two characters immediately before a
date.
Ben
------------------------------
Date: Sat, 01 Dec 2012 22:29:23 -0500
From: Kevin Walzer <kw@codebykevin.com>
Subject: Re: Insert newline before date in yyyy-mm-dd format
Message-Id: <k9ehuk$h06$1@dont-email.me>
On 12/1/12 2:22 PM, Dave Saville wrote:
>
> It did what you told it to do :-)
>
> Try s/(\d\d\d\d-\d\d-\d\d)/\n$1/g;
>
Thanks, that did the trick.
K
--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
------------------------------
Date: Sun, 02 Dec 2012 02:25:31 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: using templates effectively act Two scene 1
Message-Id: <aZSdnYDqK7gWgybNnZ2dnUVZ_vadnZ2d@supernews.com>
On 11/29/2012 05:11 PM, Ben Morrow wrote:
>
> Quoth Cal Dershowitz <cal@example.invalid>:
>> On 11/29/2012 01:52 AM, Ben Morrow wrote:
>>>
>>> Quoth Cal Dershowitz <cal@example.invalid>:
>>>>
>>>> No takers on how diamond brackets make a poor choice?
>>>
>>> Please post a minimal example that demonstrates the problem you are
>>> having. That means cutting out everything you can without making the
>>> problem go away, starting with (probably) Net::FTP.
>>
>> I have to leave town right now. What's happening is that the captions
>> are skipping. Obviously, I want them not to and have tried several
>> different things. We can assume that the cardinality of the image files
>> is equal to the paragraphs in the text file that gets read.
>
> By default <> reads by lines. See $/ in perlvar for how to make it read
> by paragraphs.
OMH, Ben,
Even the mistakes look good. You have to love the bacon fat caption for
the passing, protecting fuzz. They like bacon as much as I do.
http://merrillpjensen.com/monday_13.html
Again, thx for your Einsatz.
So if I entered correct data, this would work.
Now the Besinnung is how to make this through templates. I know that
I'm gonna need page 216.
Here's the bash script that does this:
$ cat bash3.sh
#!/bin/bash
# usage ./bash3.sh dir_from target
set -e
mkdir -p "$2"
find $1 -name "*.JPG" -printf "%p\n$2/%h-%f\n" | xargs -n2 echo cp
find $1 -name "*.JPG" -printf "%p\n$2/%h-%f\n" | xargs -n2 cp
cd $2
ls -l
mogrify -resize 640x480! *
rename 'y/A-Z/a-z/' *.JPG
ls -l
cd ..
./ftp6.pl my_ftp "$2/"
$
A Badger will do another push-up on game day.
--
Cal
------------------------------
Date: Sun, 2 Dec 2012 10:18:21 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: using templates effectively act Two scene 1
Message-Id: <dgmro9-ek4.ln1@anubis.morrow.me.uk>
Quoth Cal Dershowitz <cal@example.invalid>:
> On 11/29/2012 05:11 PM, Ben Morrow wrote:
> >
> > By default <> reads by lines. See $/ in perlvar for how to make it read
> > by paragraphs.
>
> OMH, Ben,
>
> Even the mistakes look good. You have to love the bacon fat caption for
> the passing, protecting fuzz. They like bacon as much as I do.
>
> http://merrillpjensen.com/monday_13.html
>
> Again, thx for your Einsatz.
>
> So if I entered correct data, this would work.
>
> Now the Besinnung is how to make this through templates. I know that
> I'm gonna need page 216.
>
> Here's the bash script that does this:
<snip>
>
> A Badger will do another push-up on game day.
Um...
Are you actually making any attempt whatever to make sense? Because I
didn't understand a word of that.
Ben
------------------------------
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 3830
***************************************