[29041] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 285 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 30 21:09:46 2007

Date: Fri, 30 Mar 2007 18:09:07 -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           Fri, 30 Mar 2007     Volume: 11 Number: 285

Today's topics:
    Re: Any "consumer review generators" available? <bitbucket@invalid.spam>
    Re: Fundamental pipe questions <cdalten@gmail.com>
        Isolate lines in a text file and perform replacements <r0bert_neville310@yah00.com>
    Re: Isolate lines in a text file and perform replacemen usenet@DavidFilmer.com
    Re: Isolate lines in a text file and perform replacemen <paduille.4060.mumia.w+nospam@earthlink.net>
        perl continuation character <ranrodrig@gmail.com>
    Re: perl continuation character usenet@DavidFilmer.com
    Re: perl continuation character <uri@stemsystems.com>
    Re: perl continuation character <hjp-usenet2@hjp.at>
    Re: perl continuation character <jurgenex@hotmail.com>
    Re: perl continuation character <spamtrap@dot-app.org>
    Re: perl continuation character <jurgenex@hotmail.com>
    Re: perl continuation character <wahab-mail@gmx.de>
    Re: perl continuation character <ranrodrig@gmail.com>
    Re: Perl package install dll problems <christopher.m.collins@gmail.com>
    Re: Problem installing Apache::Test <joliver@john-oliver.net>
    Re: Problem installing Apache::Test <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: readline - possible security hole <hjp-usenet2@hjp.at>
        regular expression help <bpatton@ti.com>
    Re: regular expression help <mritty@gmail.com>
    Re: regular expression help <purlgurl@purlgurl.net>
    Re: regular expression help <paduille.4060.mumia.w+nospam@earthlink.net>
    Re: Shifting Away <please@nospam.net>
    Re: Shifting Away <please@nospam.net>
    Re: Weird character issue <hjp-usenet2@hjp.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 30 Mar 2007 22:15:20 +0200
From: Schraalhans Keukenmeester <bitbucket@invalid.spam>
Subject: Re: Any "consumer review generators" available?
Message-Id: <460d6fd8$0$333$e4fe514c@news.xs4all.nl>

nullified wrote:
> On 30 Mar 2007 07:01:16 -0700, "Evil Otto" <zburnham@gmail.com> wrote:
> 
>> On Mar 30, 3:46 am, nullified <n...@null.null> wrote:
>>> On 29 Mar 2007 20:34:26 -0700, "Evil Otto" <zburn...@gmail.com> wrote:
>>>
>>>> On Mar 29, 2:19 pm, aral...@aol.com wrote:
>>>>> I am looking for a fake consumer review generator that could generate realistic looking reviews for any products, kind of like on amazon.com but generated by Artificial Intelligence. Is there a package available in your favorite programing language... thx alan
>>>> I really, really hope that you're looking to generate test data or
>>>> filler text.
>>>> If you're not, then DIAF.
>>> Die In A Fire? Drop In A Fryer? Doug Is A Fucker? Drown In A Fart?
>> Any of those would accurately describe the underlying sentiment, but I
>> had "Die In A Fire" in mind specifically.
> 
> FM!, IWRFT!
Perhaps if he finds his miracle script he can also train it to create
and 'solve' funny acronyms?


------------------------------

Date: 30 Mar 2007 18:05:43 -0700
From: "Lost Sheep Of the Porn" <cdalten@gmail.com>
Subject: Re: Fundamental pipe questions
Message-Id: <1175303143.418166.78370@n76g2000hsh.googlegroups.com>

On Mar 30, 11:56 am, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
> ["Followup-To:" header set to comp.lang.perl.misc.]
> On 2007-03-30 14:00, grocery_stocker <cdal...@gmail.com> wrote:
>
> > What's the difference between
> >  open(FOO, "=E2=94=82tr =E2=80=99[a-z]=E2=80=99 =E2=80=99[A-Z]=E2=80=99=
");
>
> How did you manage that? "=E2=94=82" is not a pipe ("|" is) and "=E2=80=
=99" is not a
> single quote ("'" is). So that code will indeed not invoke a shell,
> instead it will try to open the file "=E2=94=82tr =E2=80=99[a-z]=E2=80=99=
 =E2=80=99[A-Z]=E2=80=99" for reading.
> But I'll assume that the strange characters were introduced by your
> browser or google and that your real code does contain a pipe character
> and single quotes.
>

Yes, the strange characters were introduced by my browser.

> > and
>
> > open(FOO, =E2=80=99=E2=94=82-=E2=80=99, "tr =E2=80=99[a-z]=E2=80=99 =E2=
=80=99[A-Z]=E2=80=99");
>
> None.
>

If both these constructs are the same, then why does perlipc rattle on
about using |- for safe pipe opens. I think the following from perlipc
comes to mind.

 And here=E2=80=99s a safe pipe open for writing:

           # add error processing as above
           $pid =3D open(KID_TO_WRITE, "|-");
           $SIG{PIPE} =3D sub { die "whoops, $program pipe broke" };

           if ($pid) {  # parent
               for (@data) {
                   print KID_TO_WRITE;
               }
               close(KID_TO_WRITE) || warn "kid exited $?";

           } else {     # child
               ($EUID, $EGID) =3D ($UID, $GID);
               exec($program, @options, @args)
                   || die "can=E2=80=99t exec program: $!";
               # NOTREACHED
           }






------------------------------

Date: Fri, 30 Mar 2007 11:16:49 -0700
From: Robert Neville <r0bert_neville310@yah00.com>
Subject: Isolate lines in a text file and perform replacements
Message-Id: <qvkq03t2d8tfdd1k2kdv5dqos7afq1ledn@4ax.com>

I developed a shell script for renaming my mp3 files. I understand
that this newsgroup revolves around Perl, yet my script uses Perl for
full regular expression support (so I don't have to escape the
patterns in sed).  I just need fresh ideas for my shell script, which
may involve the Perl portions.

The script uses Perl and regular expressions to normalize the file
names. The patterns reside in a preset file.   My current development
efforts involve applying these regex patterns to playlist and xml
files. I want to process the text inside these files. Eventually, the
script would help me rename my itunes database, yet it has several
purposes beyond mp3 renaming.

The script performs a recursive search and finds files with these
extensions (m3u, sfv, and xml). It iterates (while loop) through an
external file with regular expression patterns. Then it combines the
patterns and placed them in a variable, which is passed to Perl. The
script below performs this task (yet has not been thorough tested). It
has a major shortcoming that the Perl line works on the entire file
when it should only replace the lines with mp3 pointers. Here's the
call for assistance since I am having code block. Maybe, someone could
help me with different logic or a traditional grep solution.  

find ./ -regex ".*\(m3u\|sfv\|xml\)$" -type f -print | while read FILE
	do 
		while read -r REGEX REPLACE line
		do
			CODE="$CODE; s/$REGEX/$REPLACE/g"
		done < "$PRESET"
		echo "$CODE"
		echo "perl -pi.bak -e "s/$REGEX/$REPLACE/g" $FILE"
		#PRESET may contain over twenty five regex patterns
done

btw I am doing this script in Bash, because Perl is foreign territory.


------------------------------

Date: 30 Mar 2007 12:45:15 -0700
From: usenet@DavidFilmer.com
Subject: Re: Isolate lines in a text file and perform replacements
Message-Id: <1175283915.310436.78790@n59g2000hsh.googlegroups.com>

On Mar 30, 11:16 am, Robert Neville <r0bert_neville...@yah00.com>
wrote:

> It has a major shortcoming that the Perl line works on the entire file

That's because you told Perl to work on the entire file.

> Maybe, someone could help me with different logic or a traditional
> grep solution.

You want to selectively alter MP3 tags, right?  And you don't want
your alterations to accidentally apply so some other data in the file,
right?

To do this "properly" you need program logic which can identify
specific tags, and only operate on those tags.  That's gonna be hard
to do when most of the code is a korn script.

> btw I am doing this script in Bash, because Perl is foreign territory.

Then I respectfully submit that you ought to learn a little Perl,
because Perl will make this task (and many others) rather simple.  In
fact, you can use a CPAN module (such as MP3::Info, my personal
favorite) to do most of the work (it will allow you to query and
modify specific tags).

If you post a specific example of which tag you want to modify, and a
few specific regexps you wish to apply, someone (maybe me) might post
a bit of sample code to get you started.


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



------------------------------

Date: Fri, 30 Mar 2007 20:53:45 GMT
From: "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: Isolate lines in a text file and perform replacements
Message-Id: <tNePh.19553$Jl.11124@newsread3.news.pas.earthlink.net>

On 03/30/2007 01:16 PM, Robert Neville wrote:
> [...] script below performs this task (yet has not been thorough tested). It 
> has a major shortcoming that the Perl line works on the entire file 
> when it should only replace the lines with mp3 pointers. Here's the 
> call for assistance since I am having code block. Maybe, someone could 
> help me with different logic or a traditional grep solution.  
> 
> find ./ -regex ".*\(m3u\|sfv\|xml\)$" -type f -print | while read FILE
> 	do 
> 		while read -r REGEX REPLACE line
> 		do
> 			CODE="$CODE; s/$REGEX/$REPLACE/g"
> 		done < "$PRESET"
> 		echo "$CODE"
> 		echo "perl -pi.bak -e "s/$REGEX/$REPLACE/g" $FILE"

Is this what you're looking for?

echo "perl -pi.bak -e \"s/$REGEX/$REPLACE/g if /\.mp3\b/\" $FILE"


> 		#PRESET may contain over twenty five regex patterns
> done
> 
> btw I am doing this script in Bash, because Perl is foreign territory.




------------------------------

Date: 30 Mar 2007 12:47:18 -0700
From: "ranrodrig" <ranrodrig@gmail.com>
Subject: perl continuation character
Message-Id: <1175284038.052761.43780@n76g2000hsh.googlegroups.com>

Folks, can you tell me if there is a continuation character in Perl?,
if there's one, please tell me which one is used.

TIA for your help.

Raul.



------------------------------

Date: 30 Mar 2007 13:03:39 -0700
From: usenet@DavidFilmer.com
Subject: Re: perl continuation character
Message-Id: <1175285019.619825.287860@y80g2000hsf.googlegroups.com>

On Mar 30, 12:47 pm, "ranrodrig" <ranrod...@gmail.com> wrote:
> Folks, can you tell me if there is a continuation character in Perl?,

The newline is the Perl continuation character.

(for the most part, except in heredocs or something goofy like that,
Perl doesn't care if a statement is on one line or many)


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



------------------------------

Date: Fri, 30 Mar 2007 15:06:09 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: perl continuation character
Message-Id: <x7y7le5wem.fsf@mail.sysarch.com>

>>>>> "r" == ranrodrig  <ranrodrig@gmail.com> writes:

  r> Folks, can you tell me if there is a continuation character in Perl?,
  r> if there's one, please tell me which one is used.

it is \n

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: Fri, 30 Mar 2007 22:11:31 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: perl continuation character
Message-Id: <slrnf0qrnj.nv8.hjp-usenet2@yoyo.hjp.at>

On 2007-03-30 19:47, ranrodrig <ranrodrig@gmail.com> wrote:
> Folks, can you tell me if there is a continuation character in Perl?,

No. Why would you need one?

	hp

-- 
   _  | Peter J. Holzer    | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR       | to write clearly is like blaming English for
| |   | hjp@hjp.at         | the circumlocutions of bureaucrats.
__/   | http://www.hjp.at/ |	-- Charlton Wilbur in clpm


------------------------------

Date: Fri, 30 Mar 2007 22:26:24 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: perl continuation character
Message-Id: <k8gPh.69$hI4.38@trndny08>

ranrodrig wrote:
> Folks, can you tell me if there is a continuation character in Perl?,

What is a "continuation character"?

jue




------------------------------

Date: Fri, 30 Mar 2007 18:35:31 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: perl continuation character
Message-Id: <m2ps6qiclo.fsf@local.wv-www.com>

"Jürgen Exner" <jurgenex@hotmail.com> writes:

> ranrodrig wrote:
>> Folks, can you tell me if there is a continuation character in Perl?,
>
> What is a "continuation character"?

Some languages see a newline as the end of a statement, so when you're
writing in one of those you need to escape the newline, usually with a
backslash, for multi-line statements. The escape character for those
languages is called the "continuation character" because it indicates
that the statement will continue onto the next line.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: Fri, 30 Mar 2007 22:39:20 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: perl continuation character
Message-Id: <skgPh.17$IY4.7@trndny03>

Sherm Pendley wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> writes:
>
>> ranrodrig wrote:
>>> Folks, can you tell me if there is a continuation character in
>>> Perl?,
>>
>> What is a "continuation character"?
>
> Some languages see a newline as the end of a statement, so when you're
> writing in one of those you need to escape the newline, usually with a
> backslash, for multi-line statements. The escape character for those
> languages is called the "continuation character" because it indicates
> that the statement will continue onto the next line.

You mean like for the 6502 assembler for example? I thought fixed format 
languages were a relict from the past...

jue 




------------------------------

Date: Sat, 31 Mar 2007 00:50:24 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: perl continuation character
Message-Id: <euk4i9$16j$1@mlucom4.urz.uni-halle.de>

Jürgen Exner wrote:
> Sherm Pendley wrote:
>> "Jürgen Exner" <jurgenex@hotmail.com> writes:
>>> What is a "continuation character"?
>> Some languages see a newline as the end of a statement, 
> 
> You mean like for the 6502 assembler for example? I thought fixed format 
> languages were a relict from the past...

He probably means 'bash' or the like,
where 'backslash newline' is the
'continuation' thingy.

Regards

Mirco


------------------------------

Date: 30 Mar 2007 16:12:04 -0700
From: "ranrodrig" <ranrodrig@gmail.com>
Subject: Re: perl continuation character
Message-Id: <1175296324.195641.68730@y80g2000hsf.googlegroups.com>

Folks,

Thanks a lot to all for your explanations.

Have an excellent weekend.

Raul.


Mirco Wahab ha escrito:
> J=FCrgen Exner wrote:
> > Sherm Pendley wrote:
> >> "J=FCrgen Exner" <jurgenex@hotmail.com> writes:
> >>> What is a "continuation character"?
> >> Some languages see a newline as the end of a statement,
> >
> > You mean like for the 6502 assembler for example? I thought fixed format
> > languages were a relict from the past...
>
> He probably means 'bash' or the like,
> where 'backslash newline' is the
> 'continuation' thingy.
>
> Regards
>
> Mirco



------------------------------

Date: 30 Mar 2007 11:12:06 -0700
From: "ChrisC" <christopher.m.collins@gmail.com>
Subject: Re: Perl package install dll problems
Message-Id: <1175278326.133477.32280@p77g2000hsh.googlegroups.com>

> I unset them, and start *afresh* with 'perl Makefile.PL
> J2SDK=C:/jdk1.5.0_11', accepting the defaults where prompted (which means
> that the JNI extension is built), then I find that everything builds and
> tests fine.

If you unset PERL_INLINE_JAVA_JINI then you are not testing the JNI
extension when you run the tests.  If I do that then it is all
successful too.  Problem is, I need the JNI extension, and the perl
interpreter extension, which defaults as 'n' on the perl Makefile.PL.
But, thanks for the suggestion.

Chris



------------------------------

Date: 30 Mar 2007 22:13:48 GMT
From: John Oliver <joliver@john-oliver.net>
Subject: Re: Problem installing Apache::Test
Message-Id: <slrnf0r2ss.lc8.joliver@ns.sdsitehosting.net>

On Thu, 29 Mar 2007 21:49:40 -0700, Keith Keller wrote:
> On 2007-03-30, John Oliver <joliver@john-oliver.net> wrote:
>
> [from Apache::Test build]
>> There are several ways to resolve this issue. One is to move and
>> rebuild the distribution to '/tmp/' and repeat the 'make test'
>> phase. The other is not to run 'make test' as root (i.e. building
>> under your /home/user directory).
>>
>> Can I get CPAN to install this properly, or is a manual install the only
>> way to get it installed?
>
> You probably could get CPAN to build it, but it might end up being
> more work than doing a ''manual'' install.  You already have the
> tarball downloaded by CPAN, so just build as a normal user to run
> make test.  In theory, you could use force install Apache::Test to
> install it even though make test fails, if you either don't care
> about Apache::Test passing make test, or if you have some other
> way of testing Apache::Test.

Well, a user other than root can't install it either...

Can't open perl script "/root/.cpan/build/Apache-Test-1.29/t/TEST":
Permission denied.

Even though the other user owns it and has rwx

FWIW, I'm installing it because it's one of the 18 gajillion
requirements or dependencies for RequestTracker.  I, personally, don't
care if it works or tests or what... I figure it's likely to be a
dependency of a dependency of a dependency that RT doesn't care about.

What's the quickest, easiest way to just get past this step?

-- 
* John Oliver                              http://www.john-oliver.net/ *


------------------------------

Date: Fri, 30 Mar 2007 15:52:25 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Problem installing Apache::Test
Message-Id: <aug0e4xdtm.ln2@goaway.wombat.san-francisco.ca.us>

On 2007-03-30, John Oliver <joliver@john-oliver.net> wrote:
> On Thu, 29 Mar 2007 21:49:40 -0700, Keith Keller wrote:
>>
>> You probably could get CPAN to build it, but it might end up being
>> more work than doing a ''manual'' install.  You already have the
>> tarball downloaded by CPAN, so just build as a normal user to run
>> make test.  In theory, you could use force install Apache::Test to
>> install it even though make test fails, if you either don't care
>> about Apache::Test passing make test, or if you have some other
>> way of testing Apache::Test.
>
> Well, a user other than root can't install it either...
>
> Can't open perl script "/root/.cpan/build/Apache-Test-1.29/t/TEST":
> Permission denied.

That's not what I meant.  Untar the tarball as a normal user, not in
/root, and run perl Makefile.pl && make && make test.  If it passes,
su to root and run make install.

> FWIW, I'm installing it because it's one of the 18 gajillion
> requirements or dependencies for RequestTracker.  I, personally, don't
> care if it works or tests or what... I figure it's likely to be a
> dependency of a dependency of a dependency that RT doesn't care about.
>
> What's the quickest, easiest way to just get past this step?

As I mentioned, you could always run force install Apache::Test from the
CPAN shell if you don't care about make test passing.

--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: Fri, 30 Mar 2007 20:08:47 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: readline - possible security hole
Message-Id: <slrnf0qkhf.klb.hjp-usenet2@yoyo.hjp.at>

On 2007-03-30 15:03, Paul Lalli <mritty@gmail.com> wrote:
> On Mar 30, 8:50 am, "Krivenok Dmitry" <krivenok.dmi...@gmail.com>
> wrote:
>> Suppose I use readline subroutine in my server application to read
>> one line from a socket.
>> Obviously, there may be a client, that may write something like this:
>>
>> my $request = "12345";
>> while(1)
>> {
>>    $sock->send($request);
>> }
>>
>> In this case readline() never returns, but its internal buffer will
>> continuously
>> grow.
>> Eventually, the internal buffer becomes overfull.
>
> "Hello, Doctor, suppose it hurts when I raise my right arm over my
> head...."
>
> See also:
> perldoc -f read
>
>> I can't find a way to specify maximum buffer size.
>> readline's prototype is "readline EXPR".
>> Thus, it seems to me that there is no way to specify max buffer size
>> except globally. But how?
>
> Please read the documentation for the function you're using.
[...]
>      IO::Handle->input_record_separator(EXPR)
>      $INPUT_RECORD_SEPARATOR
>      $RS
>      $/      The input record separator, newline by default.
>              [...]
>              Setting $/ to a reference to an integer, scalar
>              containing an integer, or scalar that's convertible
>              to an integer will attempt to read records instead
>              of lines,

This isn't very useful if you want to implement a line oriented protocol
(like many internet protocols). At least it isn't any more useful than
plain read. 

>> And what value should return readline() in this case?
>>
>> Is it really security hole?
>> Any comments?
>
> I don't consider poor programming practices to be security holes in
> the language.

I'm not sure if reimplementing readline with read or getc is much better
programming practice. If I was writing a forking server I'd probably
just set a suitable resource limit on memory usage and let the OS kill
the process if it gets too big. That also has the advantage that it
also works if a small input somehow causes the process to consume lots
of memory.

	hp

-- 
   _  | Peter J. Holzer    | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR       | to write clearly is like blaming English for
| |   | hjp@hjp.at         | the circumlocutions of bureaucrats.
__/   | http://www.hjp.at/ |	-- Charlton Wilbur in clpm


------------------------------

Date: 30 Mar 2007 11:51:02 -0700
From: "bpatton" <bpatton@ti.com>
Subject: regular expression help
Message-Id: <1175280662.720606.120540@p77g2000hsh.googlegroups.com>

I'm trying to set up some limitation by using regular expressions
recorded in a hash table.
How do I do an 'and' in regular expressions?

$string = '-Dz=a =Dy=b -Dx=c -Dw=d -Dv=e -Du=f -Dt=g -Ds=h';

For an or I can

$search = '-Dx=(c|g|h)';  # this came from hash value
If ($string =~ /$search/) { #  This works fine
 ...
}

Now how would I do an 'and' in any order

		             and
                       V
$search = '-Ds=(a|b|c)&&-Du=(f|g|h)';  # need both -Du and -Ds in any
order
If ($string =~ /$search/) {
 ...
}

It's probably very simple, just can't twist my mind around it :)

I can't separate the $search.  It must always be a single string.



------------------------------

Date: 30 Mar 2007 12:16:49 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: regular expression help
Message-Id: <1175282209.669235.139880@b75g2000hsg.googlegroups.com>

On Mar 30, 2:51 pm, "bpatton" <bpat...@ti.com> wrote:
> I'm trying to set up some limitation by using regular expressions
> recorded in a hash table.
> How do I do an 'and' in regular expressions?
>
> $string = '-Dz=a =Dy=b -Dx=c -Dw=d -Dv=e -Du=f -Dt=g -Ds=h';
>
> For an or I can
>
> $search = '-Dx=(c|g|h)';  # this came from hash value
> If ($string =~ /$search/) { #  This works fine
> ...
>
> }
>
> Now how would I do an 'and' in any order
>
>                              and
>                        V
> $search = '-Ds=(a|b|c)&&-Du=(f|g|h)';  # need both -Du and -Ds in any
> order
> If ($string =~ /$search/) {
> ...
>
> }
>
> It's probably very simple, just can't twist my mind around it :)
>
> I can't separate the $search.  It must always be a single string.

I would suggest fixing your algorithm to make more sense, so that it
doesn't hog tie you from using methods this messy, but until then...

if ($string =~ /Ds=[abc].*Du=[fgh]|Du=[fgh].*Ds=[abc]/) { ... }

Paul Lalli



------------------------------

Date: Fri, 30 Mar 2007 12:20:52 -0700
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: regular expression help
Message-Id: <prGdnT6wFfiJ_pDbnZ2dnUVZ_q6vnZ2d@giganews.com>

bpatton wrote:

(snipped)

> How do I do an 'and' in regular expressions?

> $string = '-Dz=a =Dy=b -Dx=c -Dw=d -Dv=e -Du=f -Dt=g -Ds=h';

> $search = '-Dx=(c|g|h)';  # this came from hash value
> If ($string =~ /$search/) { #  This works fine

> Now how would I do an 'and' in any order

> $search = '-Ds=(a|b|c)&&-Du=(f|g|h)';  # need both -Du and -Ds in any

> I can't separate the $search.  It must always be a single string.

This is untrue.

#!perl

$string = "-Ds=a-Du=h";

$search = '-Ds=(a|b|c)&&-Du=(f|g|h)';

($search1, $search2) = split (/&&/, $search);

if (($string =~ /$search1/) && ($string =~ /$search2/))
  { print "match"; }

PRINTED RESULTS:

match


Purl Gurl



------------------------------

Date: Fri, 30 Mar 2007 20:53:43 GMT
From: "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: regular expression help
Message-Id: <rNePh.19552$Jl.533@newsread3.news.pas.earthlink.net>

On 03/30/2007 01:51 PM, bpatton wrote:
> I'm trying to set up some limitation by using regular expressions
> recorded in a hash table.
> How do I do an 'and' in regular expressions?
> 
> $string = '-Dz=a =Dy=b -Dx=c -Dw=d -Dv=e -Du=f -Dt=g -Ds=h';
> 
> For an or I can
> 
> $search = '-Dx=(c|g|h)';  # this came from hash value
> If ($string =~ /$search/) { #  This works fine
> ....
> }
> 
> Now how would I do an 'and' in any order
> 
> 		             and
>                        V
> $search = '-Ds=(a|b|c)&&-Du=(f|g|h)';  # need both -Du and -Ds in any
> order

Here's a sloppy but easy way:

$search = '-D[us]=([abcfgh])'

This is less sloppy:

$search = '-Ds=([abc])|-Du=([fgh])'

> If ($string =~ /$search/) {
> ....
> }
> 
> It's probably very simple, just can't twist my mind around it :)
> 
> I can't separate the $search.  It must always be a single string.
> 

I assumed that you wanted to actually capture the a|b|c or f|g|h rather 
than just use alternation. If you don't need to capture anything, you 
can eliminate the parentheses.


------------------------------

Date: Fri, 30 Mar 2007 17:50:08 -0700
From: Xiong Changnian <please@nospam.net>
Subject: Re: Shifting Away
Message-Id: <please-A48494.17500430032007@free.teranews.com>

In article <BxUOh.20674$6z3.11150@edtnps82>,
 "John W. Krahn" <someone@example.com> wrote:

> I take it you didn't test this stuff?  :-)

I started writing code in MT-NewsWatcher, then decided indeed to switch 
to BBEdit, code and test before blatting my opinions in *.perl.*. For 
reasons which elude me now, I did not copy the code back out of BBEdit. 
During test, about the time I realized I needed to double-quote "\n", I 
decided to slim it down with: 

$, = " "; $\ = "\n";

 ... making all the trailing newlines obsolete. You caught me; you win a 
fully-operational Mac SE, loaded with important and useful software. You 
must collect your prize in person taxes are the winner's responsibility 
employees and family members are ineligible read fine print for contest 
details. 

In any case, the point of my post was all about shift and clobbering 
actual params, not about my doofus print formatting. 

Here's the actual code, in full, with output. Sorry, but you have to 
change the sub call on each run. Uncomment if you want to raise Nixon 
and Agnew from the grave; this *will* raise a fatal exception. 

sub1: clobbers $foo only
sub2: clobbers neither
sub3: clobbers $bar only
sub4: clobbers neither
sub5: clobbers neither
sub6: clobbers both

* * *

use strict;

my $foo;
my $bar;
my $error;

$, = " "; $\ = "\n";

$foo = 'goodstuff'; 
$bar = 'morestuff'; 
$error = sub1($foo, $bar);
print $foo, $bar;

#$error = sub1('nixon', 'agnew');

sub sub1 {
    $_[0] = 'bang';
    print $_[0], $_[1];
    return 0;
};
# bang morestuff
# bang morestuff

sub sub2 {
    my $stuff = shift;
    $stuff = 'bang';
    print $_[0], $_[1];
    return 0;
};
# morestuff
# goodstuff morestuff

sub sub3 {
    my $stuff = shift;
    $_[0] = 'bang';
    print $_[0], $_[1];
    return 0;
};
# bang 
# goodstuff bang

sub sub4 {
    my $stuff = shift;
    $_[1] = 'bang';
    print $_[0], $_[1];
    return 0;
};
# morestuff bang
# goodstuff morestuff

sub sub5 {
    @_ = ('bang', 'whimper');
    print $_[0], $_[1];
    return 0;
};
# bang whimper
# goodstuff morestuff

sub sub6 {
    @_[0,1] = ('bang', 'whimper');
    print $_[0], $_[1];
    return 0;
};
# bang whimper
# bang whimper

* * *
-- 
Xiong Changnian
xiong102ATxuefangDOTcom

-- 
Posted via a free Usenet account from http://www.teranews.com



------------------------------

Date: Fri, 30 Mar 2007 18:05:55 -0700
From: Xiong Changnian <please@nospam.net>
Subject: Re: Shifting Away
Message-Id: <please-6F5E5F.18055530032007@free.teranews.com>

In article <euhch3.1jc.1@news.isolution.nl>,
 "Dr.Ruud" <rvtol+news@isolution.nl> wrote:

> Xiong Changnian schreef:
> 
> > The literal 'bang' clobbers the calling context's value ('goodstuff')
> > of $foo -- bug, feature, or sloppy coder, you decide. In essence,
> > it's a call-by-reference but no dereffing is expected.
> 
> You should stop making such statements until you understand why it is
> like it is.
> But even if you don't, I won't notice it, goodbye.

Well, no need to be snooty. Enlighten me. I'm not even sure what part of 
my questionable statement offends. 

Are you questioning "call-by-reference"? I weaseled with "in essence". I 
don't think it *is* a call-by-value if I *can* clobber it. On the other 
hand, it's not a ref as Perl defines such things. 

It seems to me that the call-by-ref nature of perl is something that can 
be put to use but at times, it's exactly what's not wanted. So if actual 
params get clobbered, you can blame Perl, acclaim Perl, or blame the 
coder. I suppose I should have included the possibility of acclaiming 
the coder for his brilliant decision. I can't for the life of me think 
why you'd find this objectionable. 

But, as I suggested, you're welcome to fill me in. 

* * *

For other posters who are wondering why I dare to talk back to the 
esteemed Dr. Rude, just let me say that I'm not going to apologize for 
thinking or speaking -- today, tomorrow, or next week. If I'm wrong, I'm 
wrong; I've been wrong before, I'll be wrong again. I'm always willing 
to correct my mistakes but I'll never stop making them. 

A strength of any community is the willingness and ability to welcome 
newcomers on an equal footing.
-- 
Xiong Changnian
xiong102ATxuefangDOTcom

-- 
Posted via a free Usenet account from http://www.teranews.com



------------------------------

Date: Fri, 30 Mar 2007 20:38:14 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Weird character issue
Message-Id: <slrnf0qm8m.klb.hjp-usenet2@yoyo.hjp.at>

On 2007-03-30 17:14, Hoi-Polloi <terry_tn@yahoo.com> wrote:
> I'm using Perl 5.6, and I am seeing a very strange behavior with
> creating files with utf8 chars in the name.  Here's a little program:
>
> use utf8;
> use charnames ':full';
>
> my $A = "\x{C1}";         # latin capital letter a with acute
> my $AAA =  "_" . "$A" . "$A" . "$A";
> my $AAA1 =  "$A" . "$A" . "$A";
> system("echo 'AAA' > $AAA");
> system("echo 'AAA1' > $AAA1");
>
> If I run it, then do 'ls' I get the following:
> # ls
>     _ÃÃà            Ã?ÃÃ
> # ls | od -a
> qa-tterry-1# ls | od -a
> 0000000    _   ?  81   ?  81   ?  81  nl   ?  83   ?  81   ?  81   ?
> 81
> 0000020   nl
> 0000021
>
> In other words, the first character of the AAA1 file is not latin
> capital a acute.  I am surprised that putting "_" at the beginning of
> the string makes a difference.  What is going on here?

Firstly, please upgrade to a current version of perl. Perl 5.6.0 was the
first version with some UTF-8 support, and it has many issues which have
since been fixed. People will probably ignore your UTF-8 problems if you
don't have at least perl 5.8.1. 

Secondly, you are using system to invoke a shell command. The problem
could be a shell problem just as easily as it could be a perl problem.
If you want to demonstrate that it is a perl problem you should use
open to create the file. (and in any case you should explicitely encode
the filename).

	hp

-- 
   _  | Peter J. Holzer    | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR       | to write clearly is like blaming English for
| |   | hjp@hjp.at         | the circumlocutions of bureaucrats.
__/   | http://www.hjp.at/ |	-- Charlton Wilbur in clpm


------------------------------

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 285
**************************************


home help back first fref pref prev next nref lref last post