[27660] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9119 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 4 09:05:34 2006

Date: Tue, 4 Apr 2006 06:05:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 4 Apr 2006     Volume: 10 Number: 9119

Today's topics:
    Re: Extract first part of a string <rvtol+news@isolution.nl>
    Re: Regex Question <jurgenex@hotmail.com>
    Re: Regex Question (Anno Siegel)
    Re: Regex Question <someone@example.com>
    Re: Regex Question <rvtol+news@isolution.nl>
        Two questions on making a Perl script work on PC <rhu@mathworks.com>
    Re: Two questions on making a Perl script work on PC <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 4 Apr 2006 12:44:30 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Extract first part of a string
Message-Id: <e0tq8n.ts.1@news.isolution.nl>

Anno Siegel schreef:
> Dr.Ruud:
>> A. Sinan Unur:

>>   my ($x) = split " ", $s, 2;
>
> The limit (2) has no additional effect here, Perl supplies it anyhow.
> See "perldoc -f split", the paragraph starting "When assigning to a
> list...".

Ack. I tested with perl -e '...' and the implicit @_, and copy/pasted
that code, so that's also why the " " isn't a ' '.

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: Tue, 04 Apr 2006 10:16:41 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Regex Question
Message-Id: <dIrYf.5637$e11.4032@trnddc02>

Mike C# wrote:
> Hi I'm new to Perl regex's, and I've been racking my brain for a
> while now on this one.  Any help is appreciated.  Basically, I want
> to return all matches from the beginning of the string to a specific
> letter.  As an example, with the string "Manager" and up to the
> letter "a", I want to return the following sub-groups:
>
> M
> Man
>
> And for the word "Fishing" and up to the letter "i", I want to return:
>
> F
> Fish
>
> Thank you in advance.

Totally different idea:

reverse() the string
while() the string still contains the letter
    chop off the beginning of the string up to and including the first 
occurence of that letter
    the reverse() of the current string is another solution

jue




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

Date: 4 Apr 2006 11:43:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regex Question
Message-Id: <49f4efFnvuf9U1@news.dfncis.de>

Jürgen Exner <jurgenex@hotmail.com> wrote in comp.lang.perl.misc:
> Mike C# wrote:
> > Hi I'm new to Perl regex's, and I've been racking my brain for a
> > while now on this one.  Any help is appreciated.  Basically, I want
> > to return all matches from the beginning of the string to a specific
> > letter.  As an example, with the string "Manager" and up to the
> > letter "a", I want to return the following sub-groups:
> >
> > M
> > Man
> >
> > And for the word "Fishing" and up to the letter "i", I want to return:
> >
> > F
> > Fish
> >
> > Thank you in advance.
> 
> Totally different idea:
> 
> reverse() the string
> while() the string still contains the letter
>     chop off the beginning of the string up to and including the first 
> occurence of that letter
>     the reverse() of the current string is another solution

Why all the reversal?  Chop off the letter and everything that follows
it on each step:

    print "$str\n" while $str =~ s/$letter[^$letter]*$//;

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Tue, 04 Apr 2006 12:15:22 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Regex Question
Message-Id: <urtYf.33526$%H.21173@clgrps13>

Anno Siegel wrote:
> 
> John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
>> 
>>You don't need a regex for that:
>>
>>$ perl -le'
>>$str    = q[Manager];
>>$letter = q[a];
>>$len    = 0;
>>print substr $str, 0, $len while ( $len = index $str, $letter, $len + 1 ) > 0;
>>'
>>M
>>Man
> 
> Then again, a regex can be used:
> 
>     print substr($str, 0, $-[0]), "\n" while $str =~ /$letter/g;

The difference is that that prints the string '' if substr( $str, 0, 1 ) eq
$letter.  If you want the same behavior with substr/index change it to:

$len    = -1;
print substr $str, 0, $len while ( $len = index $str, $letter, $len + 1 ) >= 0;




John
-- 
use Perl;
program
fulfillment


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

Date: Tue, 4 Apr 2006 14:07:14 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Regex Question
Message-Id: <e0turc.s8.1@news.isolution.nl>

Anno Siegel schreef:

>     print "$str\n" while $str =~ s/$letter[^$letter]*$//;

  echo Bananana 
  | perl -nle 'print "<$1>" while /^(.*?\G.*?)a/g'

-- 
Affijn, Ruud

"Gewoon is een tijger."


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

Date: Tue, 4 Apr 2006 08:12:21 -0400
From: "Rong Hu" <rhu@mathworks.com>
Subject: Two questions on making a Perl script work on PC
Message-Id: <e0tnr5$b0a$1@fred.mathworks.com>

I'm writing a tool to auto-detect untranslated messags in M-code. I have two 
qestions to make it work on PC (DOS command window).

1. I use "find" to collect all M-code. $_ should be the same as 
$File::Find::name when I use "no_chdir => 1".
On Unix, it's true. Both give fullpathes. However, on PC, $_ gives relative 
pathes while $File::Find::name gives fullpathes.

2. I'm using either slash or backslash [/\\] as a file separator to find the 
existing translation file. Is there a better way?
Btw, I found a useful function to glue path and filename together based on 
the running platform. It's File::Spec::catfile.

Thanks in advance,

Rong 




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

Date: Tue, 04 Apr 2006 12:22:52 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Two questions on making a Perl script work on PC
Message-Id: <Xns979B5563E5AACasu1cornelledu@127.0.0.1>

"Rong Hu" <rhu@mathworks.com> wrote in
news:e0tnr5$b0a$1@fred.mathworks.com: 

> 1. I use "find" to collect all M-code. $_ should be the same as 
> $File::Find::name when I use "no_chdir => 1".
> On Unix, it's true. Both give fullpathes. However, on PC, $_ gives
> relative pathes while $File::Find::name gives fullpathes.

#!/usr/bin/perl

use strict;
use warnings;

use File::Find;

find({ wanted => \&wanted, no_chdir => 1}, $ARGV[0]);

sub wanted {
    unless ($File::Find::name eq $_ ) {
        print "$File::Find::name\n$_\n\n";
    }
}
    
__END__

D:\Home\asu1\UseNet\clpmisc> ff D:/Dload

D:\Home\asu1\UseNet\clpmisc>

D:\Home\asu1\UseNet\clpmisc> ff ..

D:\Home\asu1\UseNet\clpmisc>

Do you get different results?

> 2. I'm using either slash or backslash [/\\] as a file separator to
> find the existing translation file. Is there a better way?

Yes.

> Btw, I found a useful function to glue path and filename together
> based on the running platform. It's File::Spec::catfile.

Use it.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

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


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