[25898] in Perl-Users-Digest
Perl-Users Digest, Issue: 8126 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun May 29 14:05:35 2005
Date: Sun, 29 May 2005 11:05:06 -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 Sun, 29 May 2005 Volume: 10 Number: 8126
Today's topics:
CGI::Session <alexj@freesurf.ch>
Re: CGI::Session <alexj@freesurf.ch>
Re: CGI::Session <mark.clementsREMOVETHIS@wanadoo.fr>
Re: Force interpolation of single quoted character <nobull@mail.com>
Re: FormMail Problem (Anno Siegel)
Re: FormMail Problem <noreply@gunnar.cc>
Horn Teen Girls <teen-nadja@gmx.net>
newbie Perl question <westshestcostsheastsheri@westshestcostsheastsher.com>
Re: newbie Perl question <RedGrittyBrick@SpamWeary.foo>
Re: newbie Perl question <nobull@mail.com>
Re: Regex help: delete text only if not within quotatio <usenet739_yahoo_com_au>
Re: Regex help: delete text only if not within quotatio <nobull@mail.com>
Re: Regex help: delete text only if not within quotatio <usenet739_yahoo_com_au>
Re: Regex help: delete text only if not within quotatio <usenet739_yahoo_com_au>
regexp replace problem (Kasper)
Re: Scanning @array elements for similair content <RedGrittyBrick@SpamWeary.foo>
Re: yet another possibility to add to a syntax-err msg? (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 29 May 2005 19:00:14 +0200
From: Alexandre Jaquet <alexj@freesurf.ch>
Subject: CGI::Session
Message-Id: <4299f51f$0$1156$5402220f@news.sunrise.ch>
Hi,
Does anybody know what's the problem with my code :
#!perl -w
use strict;
use CGI;
use CGI::Session;
my $CGISESSID;
my $session;
my $query = new CGI ;
$session = new CGI::Session();
$CGISESSID = $session->id();
print "Content-type: text/html\n\n";
print "session : $CGISESSID";
error message :
CGI::Session doesn't seem to be a valid CGI::Session driver. At least
one method ('store') is missing at
C:/indigoperl/perl/site/lib/CGI/Session.pm line 150
[Sun May 29 18:57:45 2005] [error] [client 62.167.177.217]
CGI::Session::_validate_driver('CGI::Session=HASH(0x167339c)') called at
C:/indigoperl/perl/site/lib/CGI/Session.pm line 55
[Sun May 29 18:57:45 2005] [error] [client 62.167.177.217]
CGI::Session::new('CGI::Session') called at
C:/indigoperl/apache/cgi-bin/test-session.cgi line 11
[Sun May 29 18:57:45 2005] [error] [client 62.167.177.217] (in cleanup)
Can't locate auto/CGI/Session/store.al in @INC (@INC contains:
C:/indigoperl/perl/lib C:/indigoperl/perl/site/lib .) at
C:/indigoperl/perl/site/lib/CGI/Session.pm line 429
thanks in advance
------------------------------
Date: Sun, 29 May 2005 19:08:21 +0200
From: Alexandre Jaquet <alexj@freesurf.ch>
Subject: Re: CGI::Session
Message-Id: <4299f705$0$1156$5402220f@news.sunrise.ch>
Alexandre Jaquet a écrit :
> Hi,
>
> Does anybody know what's the problem with my code :
>
>
> #!perl -w
> use strict;
>
> use CGI;
> use CGI::Session;
>
> my $CGISESSID;
> my $session;
> my $query = new CGI ;
>
> $session = new CGI::Session();
> $CGISESSID = $session->id();
>
> print "Content-type: text/html\n\n";
> print "session : $CGISESSID";
>
>
> error message :
>
> CGI::Session doesn't seem to be a valid CGI::Session driver. At least
> one method ('store') is missing at
> C:/indigoperl/perl/site/lib/CGI/Session.pm line 150
> [Sun May 29 18:57:45 2005] [error] [client 62.167.177.217]
> CGI::Session::_validate_driver('CGI::Session=HASH(0x167339c)') called at
> C:/indigoperl/perl/site/lib/CGI/Session.pm line 55
> [Sun May 29 18:57:45 2005] [error] [client 62.167.177.217]
> CGI::Session::new('CGI::Session') called at
> C:/indigoperl/apache/cgi-bin/test-session.cgi line 11
> [Sun May 29 18:57:45 2005] [error] [client 62.167.177.217] (in
> cleanup) Can't locate auto/CGI/Session/store.al in @INC (@INC contains:
> C:/indigoperl/perl/lib C:/indigoperl/perl/site/lib .) at
> C:/indigoperl/perl/site/lib/CGI/Session.pm line 429
>
> thanks in advance
finally solved by modify the session creation :
$session = new CGI::Session ("driver:File", undef, {Directory =>
'C:/tmp' });
------------------------------
Date: 29 May 2005 17:10:45 GMT
From: "Mark Clements" <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: CGI::Session
Message-Id: <4299f795$0$1249$8fcfb975@news.wanadoo.fr>
Alexandre Jaquet wrote:
> Hi,
>
> Does anybody know what's the problem with my code :
>
>
> #!perl -w
> use strict;
>
> use CGI;
> use CGI::Session;
>
> my $CGISESSID;
> my $session;
> my $query = new CGI ;
>
> $session = new CGI::Session();
> $CGISESSID = $session->id();
>
> print "Content-type: text/html\n\n";
> print "session : $CGISESSID";
>
>
> error message :
>
> CGI::Session doesn't seem to be a valid CGI::Session driver. At least
> one method ('store') is missing at
> C:/indigoperl/perl/site/lib/CGI/Session.pm line 150 [Sun May 29
> 18:57:45 2005] [error] [client 62.167.177.217]
> CGI::Session::_validate_driver('CGI::Session=HASH(0x167339c)') called
> at C:/indigoperl/perl/site/lib/CGI/Session.pm line 55 [Sun May 29
> 18:57:45 2005] [error] [client 62.167.177.217]
> CGI::Session::new('CGI::Session') called at
> C:/indigoperl/apache/cgi-bin/test-session.cgi line 11 [Sun May 29
> 18:57:45 2005] [error] [client 62.167.177.217] (in cleanup) Can't
> locate auto/CGI/Session/store.al in @INC (@INC contains:
> C:/indigoperl/perl/lib C:/indigoperl/perl/site/lib .) at
> C:/indigoperl/perl/site/lib/CGI/Session.pm line 429
>
> thanks in advance
You aren't instantiating CGI::Session properly. From the documentation:
my $session = new CGI::Session(
"driver:File", undef, {Directory=>'/tmp'});
You are passing no arguments to new.
Mark
------------------------------
Date: Sun, 29 May 2005 09:37:09 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Force interpolation of single quoted character
Message-Id: <d7buvk$t6q$1@slavica.ukpost.com>
Scott Bass wrote:
> "Brian McCauley" <nobull@mail.com> wrote in message
> news:d77pkf$473$1@slavica.ukpost.com...
>
>>BTW: here's a slightly safer eval based solution
>
> I assume that should be "non eval based solution"?
No, I meant eval() based.
>> s/(\\[^"\$\@]+)/qq("$1")/eeg;
The /ee is an eval(). The above can be written:
s/(\\[^"\$\@]+)/eval qq("$1")/eg;
> both solutions work a treat. I'll go with the here doc solution; it's an
> internal, departmental script, and the end user's won't be putting cruft in
> the command line option.
OK, but in your internal documentation it's wise to describe it as
allowing arbitrary Perl.
------------------------------
Date: 29 May 2005 07:28:33 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: FormMail Problem
Message-Id: <d7bqv1$ad8$1@mamenchi.zrz.TU-Berlin.DE>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Tad McClellan wrote:
> > Gunnar Hjalmarsson wrote:
[...]
> Unlike what Christopher stated
>
> 1) pipes to other programs can be opened also when taint mode is
> enabled, and
>
> 2) the /e modifier in the expressions for unescaping URI escaped strings
>
> s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>
> isn't dangerous.
[...]
> It's funny. Normally, such incorrect statements on Perl would have
> resulted in several correcting follow-ups. Now, since they were made
> with the aim of discrediting FormMail, that did not happen.
Both have been pointed out in this thread befor now.
Anno
------------------------------
Date: Sun, 29 May 2005 11:48:25 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: FormMail Problem
Message-Id: <3fthc9F9e0apU1@individual.net>
Anno Siegel wrote:
> Gunnar Hjalmarsson wrote:
>> Unlike what Christopher stated
>>
>> 1) pipes to other programs can be opened also when taint mode is
>> enabled, and
>>
>> 2) the /e modifier in the expressions for unescaping URI escaped
>> strings
>>
>> s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>>
>> isn't dangerous.
>
> [...]
>
>> It's funny. Normally, such incorrect statements on Perl would have
>> resulted in several correcting follow-ups. Now, since they were made
>> with the aim of discrediting FormMail, that did not happen.
>
> Both have been pointed out in this thread befor now.
Yeah, by me. And you commented on the /e modifier, even if it was in a
reply to Eric...
Maybe I shouldn't have said that. Probably not. :)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 29 May 2005 14:00:14 +0200
From: "Nadja" <teen-nadja@gmx.net>
Subject: Horn Teen Girls
Message-Id: <d7ca7a$nnn$63@pomoranche.gu.net>
Look at these 18 years young and fresh horny Teen Girls:
http://www.cashteens.de.vu
Geile 18 Jaehrige Teenie Moesen tun alles fuer nur ein wenig Taschengeld:
http://www.cashteens.de.vu
------------------------------
Date: Sun, 29 May 2005 08:30:57 -0700
From: Westcoast Sheri <westshestcostsheastsheri@westshestcostsheastsher.com>
Subject: newbie Perl question
Message-Id: <BEBF2E41.74875%westshestcostsheastsheri@westshestcostsheastsher.com>
Perl is looping through thousands of sentences. Each sentence begins and
ends with a quotation mark (")
In my script, these sentences are represented by "$data[2]"
What is the "perl command" to replace the LAST occurrence of each quotation
mark, with a period and a quotation mark?
Example
"The day has come"
"He is happy"
...here's what I want:
"The day has come."
"He is happy."
I tried this:
$old = '\"';
$new = '\.\"';
sub replace_word {
local($str, $old, $new) = @_;
substr($str,rindex($str,$old),length($old)) = $new;
$str;
}
replace_word($data[2]);
...but that doesn't work.
Thank you for any help.
------------------------------
Date: Sun, 29 May 2005 15:45:42 +0000 (UTC)
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: newbie Perl question
Message-Id: <d7co36$mcg$1@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>
Westcoast Sheri wrote:
> Perl is looping through thousands of sentences. Each sentence begins and
> ends with a quotation mark (")
>
> In my script, these sentences are represented by "$data[2]"
>
> What is the "perl command" to replace the LAST occurrence of each quotation
> mark, with a period and a quotation mark?
>
> Example
>
> "The day has come"
> "He is happy"
>
> ...here's what I want:
> "The day has come."
> "He is happy."
>
> I tried this:
>
> $old = '\"';
> $new = '\.\"';
> sub replace_word {
> local($str, $old, $new) = @_;
> substr($str,rindex($str,$old),length($old)) = $new;
> $str;
> }
> replace_word($data[2]);
>
> ...but that doesn't work.
> Thank you for any help.
>
$data[2] =~ s/"$/."/;
------------------------------
Date: Sun, 29 May 2005 17:07:36 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: newbie Perl question
Message-Id: <d7cpc8$ab3$1@slavica.ukpost.com>
Westcoast Sheri wrote:
> Subject: newbie Perl question
Please put the subject of your post in the Subject of your post.
Be aware that the subject you have used will be read by mant people as
"Question I'm too lazy to figure out of myself. I'm too lazy to even
bother working out how what my question actually is".
> Perl is looping through thousands of sentences. Each sentence begins and
> ends with a quotation mark (")
>
> In my script, these sentences are represented by "$data[2]"
>
> What is the "perl command" to replace the LAST occurrence of each quotation
> mark, with a period and a quotation mark?
What do you mean by "the LAST occurrence of each quotation mark"? Each
quotation mark can onlt appear once.
> Example
>
> "The day has come"
> "He is happy"
>
> ...here's what I want:
> "The day has come."
> "He is happy."
Do you mean repace a quotation mark if it is the last character in the
string?
s/"$/."/;
Or do you mean replace the last quotation mark in the string?
s/"(?=[^"]*$)/."/;
or
s/(.*)"/$1."/;
> I tried this:
>
> $old = '\"';
> $new = '\.\"';
Perhaps you should print out those strings and look what's in them.
You'll find there really are literal backslashes in there.
> sub replace_word {
> local($str, $old, $new) = @_;
In Perl one does not use local() to to introduce variables that are
local to a subrutine or block. One uses my(). For historical reasons
local() does something rather different (for details RTFM). Note this
will not actually prevent your code from working but unless you
understand what local() does you should not use it.
If you have a book or tutorial that shows local() being used in this way
it is hopelessly out of date (my() came in at 5.0 IIRC) and you should
discard it.
> substr($str,rindex($str,$old),length($old)) = $new;
Perl has powerful regular expression based string manipulation tools.
Solutions based on substr/index/rindex can sometimes be a bit faster but
they are rarely as simple.
That said your solution should work if $old and $new contained the
correct values.
> $str;
> }
> replace_word($data[2]);
You defined replace_word() as taking 3 arguments but only pass it one.
Within replace_word the variables $old and $new will therefore be undefined.
You defined replace_word() returning a modified copy of the string
(rather than changing the string passed to it in situ) but you don't do
anything with the return value.
> Thank you for any help.
Please see the posting guidelines. They contain much useful advice on
how you can help yourself and help others to help you.
------------------------------
Date: Sun, 29 May 2005 18:24:15 +1000
From: "Scott Bass" <usenet739_yahoo_com_au>
Subject: Re: Regex help: delete text only if not within quotation marks
Message-Id: <42997c30$0$24331$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
"Damian James" <djames@thehub.com.au> wrote in message
news:slrnd93dhm.bnb.djames@puli.local...
> On Mon, 23 May 2005 18:40:17 +1000, Scott Bass said:
>> s#\*\s*(.+?)\s*\; (?!(["'])(.+?)\1)##;
>> ...
>> I want to delete text delimited by * ;, but only if * ; does not occur
>> within quotation marks.
>> ...
>> I thought I was on the right track with negative lookahead assertion???
>
> Perhaps others will explain what is going wrong with your regex, but
> I'd suggest you look at
>
> perldoc -q delimited
>
> before proceeding further. Treating quotes properly is non-trivial, is
> difficult or impossible with a regex alone, and is well supported by a
> range of modules. Foremost of these is Text::Balanced.
>
> Aside: Is that in the standard distro yet? I seem to have it and don't
> remember installing it, but that doesn't mean much ;).
>
>
> --damian
>
I've looked at:
perldoc -q delimited
Text::Balanced doc
Friedel's *Mastering Regular Expressions*
Lookahead and Lookbehind assertions
Numerous web articles
but still can't figure out how to (in pseudocode):
"delete text delimited by * and ; respectively, including the delimiters,
unless such delimiters are contained within a quoted string"
Most of the articles discuss how to extract a string delimited by quotes;
what I want to do is delete a delimited string NOT further delimited by
quotes.
Negative lookbehind seemed to hold the most promise:
(?<!")bar
matches foobar but not "bar. But, as soon as I change "bar to " bar, it
matches. And negative lookbehind requires fixed length patterns (bummer).
Any additional input appreciated.
Thanks,
Scott
------------------------------
Date: Sun, 29 May 2005 10:36:49 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Regex help: delete text only if not within quotation marks
Message-Id: <d7c2fj$ude$1@slavica.ukpost.com>
Scott Bass wrote:
> "delete text delimited by * and ; respectively, including the delimiters,
> unless such delimiters are contained within a quoted string"
> ... negative lookbehind requires fixed length patterns (bummer).
A common trick is to reexpress the problem as "delete text delimited by
* and ; respectively, including the delimiters, only if such delimiters
are preceeded by an even number of quotes".
use strict;
use warnings;
my @strings =
( 'titles "statement";',
'titles "statement"; * comment ;',
"titles '* ; statement';",
"titles '* ; statement'; * comment ;",
);
for ( @strings ) {
s/^((?:(?:[^']*'){2})*[^']*)\*[^;]*;/$1/;
print "$_\n";
}
__END__
The above only removes one comment per string. To remove all you can
put the s/// in a loop until it returns false or use \G and /g.
But before you can do either you must first consider the implications of
quote characters appearing between the * and ;. In the above there can
be unbalanced quotes between * and ; and the ; is still seen as the end
of the comment. Is this right?
A whole extra level of complexity is introduced if you want to consider
both single and double quote characters as marking strings. And yet
another if there is some way to quote quote characters within quoted
strings (other than doubling).
You need to be clear in your mind what you want to do in all possible
cases before you can implement it.
my @strings =
( 'titles "statement";',
'titles "statement"; * comment ;',
"titles '* ; statement';",
"titles '* ; statement'; * comment ;",
'titles "statement"; * Don't comment? ;',
"titles "* ; is this a comment";",
"titles '* ; statement'; * comment ; * another comment? ;",
q{titles " * This isn't a comment is it?";},
);
------------------------------
Date: Sun, 29 May 2005 23:58:20 +1000
From: "Scott Bass" <usenet739_yahoo_com_au>
Subject: Re: Regex help: delete text only if not within quotation marks
Message-Id: <4299ca7d$0$24291$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
"Brian McCauley" <nobull@mail.com> wrote in message
news:d7c2fj$ude$1@slavica.ukpost.com...
> Scott Bass wrote:
>
>> "delete text delimited by * and ; respectively, including the delimiters,
>> unless such delimiters are contained within a quoted string"
>
>> ... negative lookbehind requires fixed length patterns (bummer).
>
> A common trick is to reexpress the problem as "delete text delimited by *
> and ; respectively, including the delimiters, only if such delimiters are
> preceeded by an even number of quotes".
>
> use strict;
> use warnings;
>
> my @strings =
> ( 'titles "statement";',
> 'titles "statement"; * comment ;',
> "titles '* ; statement';",
> "titles '* ; statement'; * comment ;",
> );
>
> for ( @strings ) {
> s/^((?:(?:[^']*'){2})*[^']*)\*[^;]*;/$1/;
> print "$_\n";
> }
> __END__
>
> The above only removes one comment per string. To remove all you can put
> the s/// in a loop until it returns false or use \G and /g.
>
> But before you can do either you must first consider the implications of
> quote characters appearing between the * and ;. In the above there can be
> unbalanced quotes between * and ; and the ; is still seen as the end of
> the comment. Is this right?
No. The titles statements consist of:
titles ['"] text ['"] ;
Comments can be delimited by either /* */ or * ; and can either precede or
follow the titles statements.
Within the titles text, any comment delimiter (/* */ * ;) can appear as
text, as well as unbalanced quotes.
Quotes can appear as either:
titles 'text "text" text';
titles "text 'text' text";
titles 'text ''text'' text';
titles "text ""text"" text";
In all these scenarios, I want to remove any comments from the text of the
titles block, but leave the code itself intact.
Actually, I can live with not covering all scenarios. The most common
"tricky" scenario would be an asterisk in titles text, with either comment
style following, eg;
titles "PROC FREQ output of var1*var2"; * var2 may have missing values ;
titles "PROC FREQ output of var1*var2"; /* var2 may have missing values */
BTW, what I am working on is something like POD, but for non-Perl files. My
script extracts structured text and builds a documentation file. Within the
program source code, this structured text can appear within the titles
statements, so the programmer only has to specify the text once - once for
the titles statement (executable code) and once for the "POD" output.
> A whole extra level of complexity is introduced if you want to consider
> both single and double quote characters as marking strings. And yet
> another if there is some way to quote quote characters within quoted
> strings (other than doubling).
>
> You need to be clear in your mind what you want to do in all possible
> cases before you can implement it.
Brian, thank you *so* much for the code you posted. Much appreciated.
Here is a more realistic test case:
use strict;
use warnings;
my @strings1 = (
'1titles "statement";',
'2titles "statement"; * comment ;',
"3titles '* ; statement';",
"4titles '* ; statement'; * comment ;",
'5titles "* ; statement"; * comment ;',
"* comment ; 6titles '* ; statement'; * comment ;",
'7titles "statement"; * Don\'t comment? ;',
"8titles '* ; statement'; * comment ; * another comment? ;",
q{9titles " * This isn't a comment is it?"; * comment ;},
);
my @strings2 = (
'Atitles "statement"; /* comment */',
"Btitles '/* */ statement';",
"Ctitles '/* */ statement'; /* comment */",
"/* comment */ Dtitles '/* */ statement'; /* comment */",
'Etitles "statement"; /* Don\'t comment? */',
'Ftitles "/* */ is this a comment";',
"Gtitles '/* */ statement'; /* comment */ /* another comment? */",
q{Htitles "/* This isn't a comment is it?" */},
);
for ( @strings1 ) {
1 while s/^((?:(?:[^']*'){2})*[^']*)\*[^;]*;/$1/;
print "$_\n";
}
for ( @strings2 ) {
1 while s/^((?:(?:[^']*'){2})*[^']*)\*[^;]*;/$1/;
print "$_\n";
}
__END__
The code you posted (with the addition of the loop) works for all scenarios
except #5 and #9 (see numbers added to titles statements above). As stated
above, double quotes are also valid delimiters, so I will need to figure out
how to add them to the RE. Scenarios #4 & #5 are the most common; I will
need to code for #5, but can live with some of the other scenarios failing.
I didn't add the scenarios in @strings2 in my previous posts because I was
hoping that, with a solution to @strings1, I could work out how to code
@strings2. My mistake, mea culpa.
The sad fact is, I've come to realize I'm over my head here regarding these
"fancy" regular expressions (as described here
http://www.unix.org.ua/orelly/perl/prog3/ch05_10.htm). I've got the various
O'Reilly Perl books, including Mastering Regular Expressions, but I'm going
to have to read, re-read, re-read, and hack around until I "master regular
expressions" (as the title suggests :-/)
I don't expect you to do my work, so I'll just have to study and hack around
with this until I get it to work.
I really, *really* appreciate your most helpful replies to my recent posts.
Kind Regards,
Scott
------------------------------
Date: Mon, 30 May 2005 00:13:53 +1000
From: "Scott Bass" <usenet739_yahoo_com_au>
Subject: Re: Regex help: delete text only if not within quotation marks
Message-Id: <4299ce22$0$24327$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
"Scott Bass" <usenet739_yahoo_com_au> wrote in message
news:4299ca7d$0$24291$5a62ac22@per-qv1-newsreader-01.iinet.net.au...
[snip]
> Quotes can appear as either:
>
> titles 'text "text" text'; ###
> titles "text 'text' text"; ###
> titles 'text ''text'' text';
> titles "text ""text"" text";
Sorry, these are also valid:
titles 'text "unbalanced quotes';
titles "text 'unbalanced quotes"; <<<
titles 'text ''unbalanced quotes';
titles "text ""unbalanced quotes";
The ### lines above above are the most common, but all of these are valid.
The <<< is most often used with contractions in the title text.
------------------------------
Date: 29 May 2005 09:49:06 -0700
From: kcecek@gmail.com (Kasper)
Subject: regexp replace problem
Message-Id: <5ee1860d.0505290849.1e36557b@posting.google.com>
Hello,
I got a problem with regular expressions.
My input data look like this :
aaa,bbcc,bbdd,bbee
aaa,bbcc,bbee,bbff,bbgg,bbhh
(There could be many elements like (,[^,]*) in one line)
I want to substitute every second and next element with first element.
The result of presented lines should be :
aaabbcc,aaabbdd,aaabbee
aaabbcc,aaabbee,aaabbff,aaabbgg,aaabbhh
It don't have to be one line substitution.
Please help - I have no idea how to do this and I tried almost everything.
Kasper
------------------------------
Date: Sun, 29 May 2005 15:37:26 +0000 (UTC)
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Scanning @array elements for similair content
Message-Id: <d7cnjk$n36$1@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com>
Randy wrote:
> Hello,
>
> I have a text file that stores names and email addresses. This data is built
> from a feedback form on my website. Here is the format of my textfile
> entries:
>
> Dan Smith,dan@email.com
> Mike Roberts,mike@yahoo.com
> Steve Anderson,steve@goto.com
>
> and so on.
>
> As you can see, it's pretty much a standard CSV textfile. Overtime, this
> database has grown very big, and there are several duplicate email addresses
> in the data. Until recently I have had to visually go through the data and
> remove duplicate email addresses I can find, regardless of what is found in
> the name field. I am seeking assistance on how I could write a script that
> would scan each line, separate the names field from the email address field,
> then scan and remove duplicates. So far all I have is the following:
>
> #!/usr/bin/perl
>
> use CGI;
> use CGI::Carp qw(fatalsToBrowser);
> use strict;
>
> my @data, $data, $name, $email;
>
> open (FH, "<data.txt") or die "Can't open file: $!";
> @data=<FH>;
> close(FH);
>
> foreach $data (@data) {
> chomp ($data);
> ($name,$email)=split(/\,/,$data);
>
> \\ Missing scan for duplicates and removal code here \\
> }
>
> open (FH, ">data.txt") or die "Can't open file: $!";
> print FH @data;
> close(FH);
>
> Yes I am a newbie Perl programmer. I'm not very good at brainstorming an
> approach to sorting/matching routines. I would very much appreciate some
> help understanding and building the final element. Another complication is
> what if there are two identical email addresses but one is all caps and the
> other isn't. I'm not looking for someone to write me the code I need,
> instead to point me in the right direction so that I actually learn
> something and forward my Perl skills. Thankx everyone.
>
Rather than removing duplicates, I'd not insert them
#!perl
use strict;
use warnings;
open my $fh, '<', 'data.txt'
or die "unable to open data.txt because $!";
while (<$fh>) {
chomp;
my ($name, $address) = split(/\,/,$_,2);
print "$name, $address\n" unless $seen{$address}++:
}
close $fh;
Untested.
------------------------------
Date: 29 May 2005 07:47:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: yet another possibility to add to a syntax-err msg?
Message-Id: <d7bs23$ad8$2@mamenchi.zrz.TU-Berlin.DE>
David Combs <dkcombs@panix.com> wrote in comp.lang.perl.misc:
> Subject: yet another possibility to add to a syntax-err msg?
>
> | 698 ==/dkcjunk==> /me-FIRST-in-PATH-bin/perl-5.8.6/bin/perl5.8.6 -c
> -w traverse-via-SOURCE-stmts.pl .myalias
This causes the output below? I don't see any reference to
"diagnostics" or "splain" that would.
> | syntax error at traverse-via-SOURCE-stmts.pl line 112, near
> "aryOfAliasObjRefs["
> | traverse-via-SOURCE-stmts.pl had compilation errors (#1)
> | (F) Probably means you had a syntax error. Common reasons include:
> |
> | A keyword is misspelled.
> | A semicolon is missing.
> | A comma is missing.
> | An opening or closing parenthesis is missing.
> | An opening or closing brace is missing.
> | A closing quote is missing.
[...]
> But, here's what's actually at line 112:
>
> aryOfAliasObjRefs[$numAliases++] = $aliasObjRef;
>
> , the error being the missing sigil.
>
> Please add this possiblity to the other six.
The list above doesn't claim to be complete, as "...reasons include"
indicates. There must be dozens more possible causes for syntax errors
that aren't mentioned. It's a reasonable list of the more frequent
ones. I don't see compelling reason to add more.
Anno
------------------------------
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 8126
***************************************