Re: regex problem?

2015-11-25 Thread Andrew Solomon
The only problem I can see is that you want UPPERCASE-1234 and your regex
has lowercase. Try

(\A[A-Z]+)   # match and capture leading alphabetics


Andrew

p.s Why not add "use strict; use warnings", "my $var;" and wear a seat belt
when you're driving?:)



On Wed, Nov 25, 2015 at 5:09 PM, Rick T  wrote:

> The following code apparently is not doing what I wanted. My intention was
> to confirm that the general format of  $student_id was this: several
> uppercase letters followed by a hyphen followed by several digits. If not,
> it would trigger the die. Unfortunately it seems to always trigger the die.
> For example, if I let student_id = triplett-1, the script dies. I’m a
> beginner, so I often have trouble seeing the “obvious.” Any suggestions
> will be appreciated!
>
> if  ( $student_id =~
> /
> (\A[a-z]+)  # match and
> capture leading alphabetics
> -   # hyphen
> to separate surname from number
> ([0-9]+\z)  # match and
> capture trailing digits
> /xms# Perl Best
> Practices
> ) {
> $student_surname = $1;
> $student_number  = $2;
> }
> else {
> die "Bad general form for student_id: $student_id"
> };
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


-- 
Andrew Solomon

Mentor@Geekuni http://geekuni.com/
http://www.linkedin.com/in/asolomon


Re: regex problem?

2015-11-25 Thread Shawn H Corey
On Wed, 25 Nov 2015 17:22:04 +
Andrew Solomon  wrote:

> The only problem I can see is that you want UPPERCASE-1234 and your
> regex has lowercase. Try
> 
> (\A[A-Z]+)   # match and capture leading alphabetics

Please put the anchor outside the capture. And you could use the POSIX
conventions:

m{ \A ([[:upper:]]+) }msx;

This will work with non-English characters. :)


-- 
Don't stop where the ink does.
Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex problem

2010-11-05 Thread Shawn H Corey

On 10-11-05 09:34 AM, jm wrote:

i have csv files in the following format, where some fields are
enclosed in double quotes if they have commas embedded in them and all
other fields are simply comma-delimited without any encapsulation


The best way to deal with CSV is to use a module from CPAN.

Text::CVS  http://search.cpan.org/~makamaka/Text-CSV-1.20/lib/Text/CSV.pm

Text::CSV_XS  http://search.cpan.org/~hmbrand/Text-CSV_XS-0.76/CSV_XS.pm


--
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early  often.

Eliminate software piracy:  use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex problem

2010-11-05 Thread Robert Wohlfarth
On Fri, Nov 5, 2010 at 8:34 AM, jm jm5...@gmail.com wrote:

 changing the formatting of the source file to enclose all fields in
 double quotes is not an option.  i'm trying to figure out a regex,
 split, or some other functionality that will allow me to either

 1. wrap each 'bare' field in double quotes (ignoring the embedded
 commas in the encapsulated fields)or
 2. extract each field, automatically determining if commas should be
 ignored inside double quotes


Try the Text::CSV
modulehttp://search.cpan.org/%7Emakamaka/Text-CSV-1.20/lib/Text/CSV.pm.
It handles all of these details for you.

-- 
Robert Wohlfarth


Re: regex problem

2010-11-05 Thread jm
i appreciate the tips.  unfortunately, adding modules to this server
is not currently possible.  does anyone have a more 'hands-on'
solution?


On Fri, Nov 5, 2010 at 8:53 AM, Shawn H Corey shawnhco...@gmail.com wrote:
 On 10-11-05 09:34 AM, jm wrote:

 i have csv files in the following format, where some fields are
 enclosed in double quotes if they have commas embedded in them and all
 other fields are simply comma-delimited without any encapsulation

 The best way to deal with CSV is to use a module from CPAN.

 Text::CVS  http://search.cpan.org/~makamaka/Text-CSV-1.20/lib/Text/CSV.pm

 Text::CSV_XS  http://search.cpan.org/~hmbrand/Text-CSV_XS-0.76/CSV_XS.pm


 --
 Just my 0.0002 million dollars worth,
  Shawn

 Programming is as much about organization and communication
 as it is about coding.

 The secret to great software:  Fail early  often.

 Eliminate software piracy:  use only FLOSS.

 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/






-- 
since this is a gmail account, please verify the mailing list is
included in the reply to addresses

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: regex problem

2010-11-05 Thread Ken Slater
From: jm [mailto:jm5...@gmail.com] 
Sent: Friday, November 05, 2010 10:21 AM

i appreciate the tips.  unfortunately, adding modules to this server
is not currently possible.  does anyone have a more 'hands-on'
solution?

Take a look at the Text::ParseWords module. I believe it should be
installed. perldoc Text::ParseWords.
I have used it for similar problems in the past.
Ken

On Fri, Nov 5, 2010 at 8:53 AM, Shawn H Corey shawnhco...@gmail.com
wrote:
 On 10-11-05 09:34 AM, jm wrote:

 i have csv files in the following format, where some fields are
 enclosed in double quotes if they have commas embedded in them and all
 other fields are simply comma-delimited without any encapsulation

 The best way to deal with CSV is to use a module from CPAN.

 Text::CVS  http://search.cpan.org/~makamaka/Text-CSV-1.20/lib/Text/CSV.pm

 Text::CSV_XS  http://search.cpan.org/~hmbrand/Text-CSV_XS-0.76/CSV_XS.pm


 Just my 0.0002 million dollars worth,
  Shawn






-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Regex problem

2009-12-26 Thread Chris Charley


- Original Message - 
From: Owen rc...@pcug.org.au

Newsgroups: perl.beginners

Hello Owen




To check the date passed with a script, I first check that the date
is in the format 20dd (20 followed by 6 digits exactly)

But the regex is wrong, tried /^20\d{6}/,/^20\d{6,6}?/,/^20\d{6,}?/ and
while a 7 or lesser digit number fails, eg 2009101, a 9 digit number,
like 200910103 does not fail.



unless ( $ARGV[2] =~ /^20\d{6}?/ ) { print




unless ( $ARGV[2] =~ /^20\d{6}$/) ...

If the end of line anchor is used, '$', the regex will accept an 8 digit 
number if it's the only entry in $ARGV[2]


Chris


$ARGV[2]\tdate format is MMDD, eg 20091031\n; }


How do I get the regex to fail a 9 digit number


I suppose as a work around, I could say;

unless ((length($ARGV[2]) == 8) and ( $ARGV[2] =~ /^20/){fail}

TIA


Owen 



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Regex problem

2009-12-21 Thread Shawn H Corey
jbl wrote:
 I have a lengthy list of data that I read in. I have substituted a one
 line example using __DATA__.
 The desired output would be
 91416722  243rd St
 
 I am getting this as output
 
 91416722rd St   - just the rd St
 
 The capturing reference on (\s)..$1
 
 is not working
 
 # Intent
 # Look for 243 preceded by any white space, followed by a space char
 # Capture the whitespace as $1
 # Replace with whatever the leading whitespace was, then the number,
 then the suffix rd and then the trailing space char
 
 Basically add the suffix rd to the number 243, ie...243rd
 I can do something else but I was wondering what I am doing wrong here
 Thanks
 jbl
 
 
 #!/usr/bin/perl -w
  use strict;
 
 open MY_OUTPUT_FILE,  Export_Output_mod.txt or die Can't write to
 out.txt: $!;
 
  while ( defined ( my $line = DATA ) ) {
$line =~ s/(\s)243 /$1243rd /g;

 $line =~ s/(\s)243 /${1}243rd /g;


print MY_OUTPUT_FILE $line;
}
 
 close MY_OUTPUT_FILE;
 
 __END__
 91416722  243 St
 
 


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Regex problem

2009-12-21 Thread Robert Wohlfarth
On Mon, Dec 21, 2009 at 9:11 AM, jbl jbl...@gmail.com wrote:

 The desired output would be
 91416722243rd St

 I am getting this as output

 91416722rd St   - just the rd St

 snip

 while ( defined ( my $line = DATA ) ) {
   $line =~ s/(\s)243 /$1243rd /g;
   print MY_OUTPUT_FILE $line;
   }


Try this: $line =~ s/(\s)243 /${1}243rd /g;

Without the braces, Perl is looking for match number 1,243! Braces separate
the 1 from the 243.

-- 
Robert Wohlfarth


Re: Regex problem

2009-03-11 Thread howa
Hi,

On Mar 11, 1:16 am, nore...@gunnar.cc (Gunnar Hjalmarsson) wrote:

 I would do:

      if ( $a =~ /\.(?:html|jpg)$/i )

 Please readhttp://perldoc.perl.org/perlretut.htmland other appropriate
 docs.

Read the doc, but how to negate the Non-capturing groupings ?

use strict;

my $a = 'a.gif';

if ($a =~ /^(?:html|jpg)/gi) {
print 'not html or jpg';

}

Thanks,


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Regex problem

2009-03-11 Thread Jim Gibson
On 3/10/09 Tue  Mar 10, 2009  8:41 PM, howa howac...@gmail.com
scribbled:

 Hi,
 
 On Mar 11, 1:16 am, nore...@gunnar.cc (Gunnar Hjalmarsson) wrote:
 
 I would do:
 
      if ( $a =~ /\.(?:html|jpg)$/i )
 
 Please readhttp://perldoc.perl.org/perlretut.htmland other appropriate
 docs.
 
 Read the doc, but how to negate the Non-capturing groupings ?
 
 use strict;
 
 my $a = 'a.gif';
 
 if ($a =~ /^(?:html|jpg)/gi) {
 print 'not html or jpg';
 
 }

That will test if $a starts with 'html' or 'jpg'. To test for a non-match,
use the !~ operator:

If( $a !~ /(?:htm|jpg)$/gi ) {
  print not html or jpg\n;
}



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Regex problem

2009-03-11 Thread howa
Hello,

On Mar 12, 12:34 am, jimsgib...@gmail.com (Jim Gibson) wrote:
 That will test if $a starts with 'html' or 'jpg'. To test for a non-match,
 use the !~ operator:


I can't, since I will add more criteria into the regex,

e.g.

I need to match a.* , except a.html or a.jpg

 if ( $a =~ /a\.(?:html|jpg)$/i ) # of course this one does not work.


Thanks.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Regex problem

2009-03-11 Thread Chas. Owens
On Wed, Mar 11, 2009 at 12:53, howa howac...@gmail.com wrote:
 Hello,

 On Mar 12, 12:34 am, jimsgib...@gmail.com (Jim Gibson) wrote:
 That will test if $a starts with 'html' or 'jpg'. To test for a non-match,
 use the !~ operator:


 I can't, since I will add more criteria into the regex,

 e.g.

 I need to match a.* , except a.html or a.jpg

  if ( $a =~ /a\.(?:html|jpg)$/i ) # of course this one does not work.
snip

You want a zero-width-negative-look-ahead:

#!/usr/bin/perl

use strict;
use warnings;

my @a = qw/a.html a.jpg a.gif/;

for my $s (@a) {
print $s , $s =~ /a[.](?!html|jpg)/ ? matches : does not match,
\n;
}

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Regex problem, #.*# on new line

2009-03-11 Thread John W. Krahn

Brent Clark wrote:

Hiya


Hello,

I got a string like so, and for the likes of me I can get regex to have 
it that each line is starts with #abc#.


my $a = 
#aaa#message:details;extra:info;variable:times;#bbb#message:details;extra:info;variable:times;#ccc#not:always;the:same;ts:14:00.00;; 


$a =~ s/(?!#.#)/$1\n/i;


You are using a zero-width negative look-behind assertion which does not 
capture its contents.  You are using a pattern that matches a total of 
three characters but you say you want to match five characters.  You are 
using the /i option but there are no characters in the pattern that are 
affected by the /i option.


You probably want something like:

$x =~ s/(#...#[^#]*)/$1\n/g;



John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Regex problem

2009-03-10 Thread Jim Gibson
On 3/10/09 Tue  Mar 10, 2009  8:19 AM, howa howac...@gmail.com
scribbled:

 Hello,
 
 Consider the code:
 #===
 
 use strict;
 
 my $a = 'a.jpg';
 
 if ($a =~ /(html|jpg)/gi) {
 print 'ok';
 }
 
 #===
 
 
 Is the brucket () must be needed? Since I am not using back
 reference, are there a better way?

No, the parentheses are not need in this simple case. The pattern
/html|jpg/i will work fine (you don't need the 'g' modifier since you are
only looking for one match).

However, if you want other elements in your pattern, you may need
parentheses to group sub-elements. For example, if you wanted to match only
if the 'html' or 'jpg' were at the end of the string, then /html|jpg$/ will
not work, as this pattern will match 'html' anywhere in the string. You will
have to use /html$|jpg$/ or /(html|jpg)$/. Non-capturing parentheses can be
used for clustering without capturing, as in /(?:html|jpg)$/.

You can make your regexs a little more readable with the 'x' modifier:

/ html | jpg /ix



 



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Regex problem

2009-03-10 Thread Chas. Owens
On Tue, Mar 10, 2009 at 11:19, howa howac...@gmail.com wrote:
 Hello,

 Consider the code:
 #===

 use strict;

 my $a = 'a.jpg';

 if ($a =~ /(html|jpg)/gi) {
    print 'ok';
 }

 #===


 Is the brucket () must be needed? Since I am not using back
 reference, are there a better way?
snip

Since you have no other patterns in the regex you do not need the
parentheses.  If you had other patterns and wanted to avoid the
slowdown associated with backreferences you could use the
group-non-capturing parentheses:

/foo[.](?:html|jpg)/

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Regex problem

2009-03-10 Thread Gunnar Hjalmarsson

howa wrote:

Hello,

Consider the code:
#===

use strict;

my $a = 'a.jpg';

if ($a =~ /(html|jpg)/gi) {
print 'ok';
}

#===


Is the brucket () must be needed?


Parentheses. What happened when you tried without them? And why the /g 
modifier?



Since I am not using back reference, are there a better way?


I would do:

if ( $a =~ /\.(?:html|jpg)$/i )

Please read http://perldoc.perl.org/perlretut.html and other appropriate 
docs.


--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Regex problem with accented characters

2007-03-27 Thread Mumia W.

On 03/27/2007 03:34 AM, Beginner wrote:

Hi,

I am trying to extract the iso code and country name from a 3 column 
table (taken from en.wikipedia.org) and have noticed a problem with 
accented characters such as Ô.


Below is my script and a sample of the data I am using. When I run 
the script the code beginning CI for Côte d'Ivoire returns the string


CI\tC where as I had hoped for CI\tCôte d'Ivoire

Does anyone know why \w+ does include Côte d'Ivoire and how I can get 
around it in future?


TIA,
Dp.


 extract.pl 
#!/usr/bin/perl

use strict;
use warnings;

my $file = 'iso-alpha2.txt';

open(FH,$file) or die Can't open $file: $!\n;
while (FH) {
chomp;
next if ($_ !~ /^\w{2}\s+/);
	my ($code,$name) = ($_ =~ 
/^(\w{2})\s+(\w+\s\w+\s\w+s\w+|\w+\s\w+\s\w+|\w+\s\w+|\w+)/);

print $code\t$name\n;
}
===

 sample data 
...snip
BY  Belarus Previously named Byelorussian S.S.R.
BZ  Belize  
CA  Canada  
CC  Cocos (Keeling) Islands 
CD 	Congo, the Democratic Republic of the 	Previously named Zaire 
ZR

CF  Central African Republic
CG  Congo   
CH 	Switzerland 	Code taken from Confoederatio Helvetica, its 
official Latin name

CI  Côte d'Ivoire   
CK  Cook Islands
CL  Chile   
CM 	Cameroon 
===




It's partly the encoding. Put «use encoding iso-8859-1;» at the top of 
your program, and there will be a little improvement. However, that only 
gets you as far as Côte d; I doubt there is any encoding where 
apostrophe is in \w.


It's probably best to create an expression that contains all of the 
characters you may want. That would include accented characters and the 
apostrophe in this case.


Also, I advise you to use an programmer's editor that supports syntax 
highlighting. My VIM shows me that you missed the backslash that is 
supposed to be on the fourth \s in your regular expression.




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Regex problem with accented characters

2007-03-27 Thread Rob Dixon

Beginner wrote:

Hi,

I am trying to extract the iso code and country name from a 3 column 
table (taken from en.wikipedia.org) and have noticed a problem with 
accented characters such as Ô.


Below is my script and a sample of the data I am using. When I run 
the script the code beginning CI for Côte d'Ivoire returns the string


CI\tC where as I had hoped for CI\tCôte d'Ivoire

Does anyone know why \w+ does include Côte d'Ivoire and how I can get 
around it in future?


TIA,
Dp.


 extract.pl 
#!/usr/bin/perl

use strict;
use warnings;

my $file = 'iso-alpha2.txt';

open(FH,$file) or die Can't open $file: $!\n;
while (FH) {
chomp;
next if ($_ !~ /^\w{2}\s+/);
my ($code,$name) = ($_ =~ 
/^(\w{2})\s+(\w+\s\w+\s\w+s\w+|\w+\s\w+\s\w+|\w+\s\w+|\w+)/);
print $code\t$name\n;
}
===

 sample data 
...snip
BY  Belarus Previously named Byelorussian S.S.R.
BZ  Belize  
CA  Canada  
CC  Cocos (Keeling) Islands 
CD 	Congo, the Democratic Republic of the 	Previously named Zaire 
ZR

CF  Central African Republic
CG  Congo   
CH  Switzerland Code taken from Confoederatio Helvetica, its official 
Latin name
CI  Côte d'Ivoire   
CK  Cook Islands
CL  Chile   
CM 	Cameroon 
===


Ordinarily the range of characters mapped by \w is limited to [0-9A-Za-z_].
However, if you put 'use locale' at the start of your program this will be
extended to include the accented alpha characters as well (see perldoc
perllocale).

However, this will still not solve your problem, as the apostrophe in
Côte d'Ivoire will still not match \w and you will end up with
CI\tCôte d. I suggest you change your regex to simply match any
character at all up to the end of the line, like this:

 while (FH) {
   chomp;
   next unless /^(\w\w)\s+(.+?)\s*$/;
   my ($code, $name) = ($1, $2);
   print $code\t$name\n;
 }

which will give the result you desire.

But you still have the problem that the line for Zaire has no text and
will not match the regex anyway!

Hope this helps.

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Regex problem with accented characters

2007-03-27 Thread Rob Dixon

Beginner wrote:


/^(\w{2})\s+(\w+\s\w+\s\w+s\w+|\w+\s\w+\s\w+|\w+\s\w+|\w+)/);


It's worth noting that this could be written:

/^(\w{2})\s+(\w+(?:\s\w+)*)/);

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: regex problem

2006-02-16 Thread Jay Savage
On 2/15/06, anand kumar [EMAIL PROTECTED] wrote:


 John W. Krahn [EMAIL PROTECTED] wrote:anand kumar wrote:
  Hi all,

 Hello,

  I have the following problem in the following regex replace.
 
  $line=~s!\b($name)\b!$1!g;
 
  here this regex finds the exact matching of the content in $name and does
  the needed but in some examples the variable $name may contain backslash
  characters like 'gene\l=s\' , in this type of cases the replace string does
  not work so i have removed '\b' on either side and used the following
 
  $line=~s!(\Q$name\E)!$1!g;
 
  This works fine but the problem is that the replacement is not done on the
  exact word but also on substrings which is unnecessary.
 
  if i use both \b\b and \Q\E then the code fails to replace.
 
  please send suggestions in this regard

 $line=~s!\b(\Q$name\E)\b!$1!g;

Try this: if $name is a single-quoted string:

$name = quotemeta($name);
$line =~ s|($name)|au$1|;

If $name is a double-quoted string:

   $name = quotemeta(quotemeta($name));
   $line =~ s|($name)|au$1|;

It's preferable, though for $name to be single-quoted, because Perl
will do some interpolation at the time the string is saved, and
depending on your system, strange things can happen. For instance, the
following are not all equal:

$name = quotemeta(\aball); # $name gets '\\x07ball'
$name = '\aball';# $name gets '\aball'
$name = \aball; $name = quotemeta($name);
# $name gets '\\x07ball'

This is because the double-quoted string is interpolated before it is
assigned to a variable or passed to a function and the
metacharacter--in this case '\a', the escape sequence for the ASCII
bell character--is already interpolated.

HTH,

-- jay
--
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.dpguru.com  http://www.engatiki.org

values of β will give rise to dom!


Re: regex problem

2006-02-15 Thread anand kumar


John W. Krahn [EMAIL PROTECTED] wrote:anand kumar wrote:
 Hi all,

Hello,

 I have the following problem in the following regex replace.
 
 $line=~s!\b($name)\b!$1!g;
 
 here this regex finds the exact matching of the content in $name and does
 the needed but in some examples the variable $name may contain backslash
 characters like 'gene\l=s\' , in this type of cases the replace string does
 not work so i have removed '\b' on either side and used the following
 
 $line=~s!(\Q$name\E)!$1!g;
 
 This works fine but the problem is that the replacement is not done on the
 exact word but also on substrings which is unnecessary.
 
 if i use both \b\b and \Q\E then the code fails to replace.
 
 please send suggestions in this regard

$line=~s!\b(\Q$name\E)\b!$1!g;



John
-- 
use Perl;
program
fulfillment
   
  Hi john,
   
   i have tried the above method but the replace ment is done .
  regards
  anand


-
 Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time.

Re: regex problem

2006-02-14 Thread John W. Krahn
anand kumar wrote:
 Hi all,

Hello,

 I have the following problem in the following regex replace.
 
 $line=~s!\b($name)\b!au$1!g;
 
 here this regex finds the exact matching of the content in $name and does
 the needed but in some examples the variable $name may contain backslash
 characters like 'gene\l=s\' , in this type of cases the replace string does
 not work so i have removed '\b' on either side and used the following
 
 $line=~s!(\Q$name\E)!au$1!g;
 
 This works fine but the problem is that the replacement is not done on the
 exact word but also on substrings which is unnecessary.
 
 if i use both \b\b and \Q\E then the code fails to replace.
 
 please send suggestions in this regard

$line=~s!\b(\Q$name\E)\b!au$1!g;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Regex Problem.

2005-08-18 Thread Wiggins d'Anconia
Sara wrote:
 I am at a loss here to generate REGEX for my problem.
 
 I have an input query coming to my cgi script, containg a word (with or 
 without spaces e.g. blood Globin Test etc).
 What I am trying to do is to split this word (maximum of 3 characters) and 
 find the BEST possible matching words within mySQL database. For example if 
 the word is blood
 
 I want to get results using regex: 
 
 for blood: check(blo) then check(loo)  check(ood)
 for Globin Test: check(Glo) then check(lob)  check(obi) check(bin) 
 check(Tes) check(est)
 
 TIA.


Sounds like you need a split then a substr rather than a regex,
though I suppose it would work if you really wanted one, I wouldn't.

perldoc -f split
perldoc -f substr

It will also be faster to combine everything into one select rather than
for each possible token, but at the least if you are going to do
multiple selects use 'prepare' with placeholders and only prepare the
query once.

So,

-- UNTESTED --

my @tokens = split ' ', $entry;
my @words;
foreach my $token (@tokens) {
  push @words, substr $token, 0, 3;
  push @words, substr $token, -3, 3;
}

(or you can put the following into the above foreach however you would like)

my $where = '';
my @bind;
foreach my $word (@words) {
  $where .= ' OR ' if $where ne '';
  $where .= (def LIKE ?);
  push @bind, %$word%;
}

my $sth = $dbh-prepare(SELECT * FROM medical WHERE $where);
$sth-execute(@bind);

while (my @row = $sth-fetchrow_array) {
  print join ' ', @row;
  print \n;
}

This also prevents SQL injection by quoting the query words properly.

 Sara.


http://danconia.org

 sub check {
 my $check = $dbh - prepare(SELECT * FROM medical WHERE def LIKE '%$query%' 
 );
 $check-execute();
 while (my @row = $check - fetchrow_array()) {
 print blah blah blah\n;
 }
 }
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Regex Problem.

2005-08-18 Thread Sara

That's worked like a charm, You ALL are great.

Thanks everyone for help.

Sara.


- Original Message - 
From: [EMAIL PROTECTED]

To: 'Sara' [EMAIL PROTECTED]
Sent: Thursday, August 18, 2005 10:50 PM
Subject: RE: Regex Problem.



Hi Sara,

what is about somthing like
$string = 'blood';
for($i=0; $i=length($string)-3;$i++) {

check(substr($string,$i,3));
}



Mit freundlichen Grüssen
   Ihr echtwahr.Webmaster


http://www.echtwahr.de
http://www.echtwahr.com

-Original Message-
From: Sara [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 18, 2005 5:48 PM
To: beginners-cgi@perl.org
Subject: Regex Problem.

I am at a loss here to generate REGEX for my problem.

I have an input query coming to my cgi script, containg a word (with or
without spaces e.g. blood Globin Test etc).
What I am trying to do is to split this word (maximum of 3 characters) 
and

find the BEST possible matching words within mySQL database. For example
if the word is blood

I want to get results using regex:

for blood: check(blo) then check(loo)  check(ood)
for Globin Test: check(Glo) then check(lob)  check(obi)
check(bin) check(Tes) check(est)

TIA.

Sara.

sub check {
my $check = $dbh - prepare(SELECT * FROM medical WHERE def LIKE
'%$query%' );
$check-execute();
while (my @row = $check - fetchrow_array()) {
print blah blah blah\n;
}
}







--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: regex problem

2005-07-01 Thread Chris Devers
On Fri, 1 Jul 2005, Moon, John wrote:

 The following is not returning what I had expected...
 
 $a= q{/var/run};
 $home = q{/var/ru};
 print Yes - $a like $home\n if $a =~ /^$home/;
 
 I would have assumed  that /var/run would NOT be like /var/ru just 
 as /var/run is not like /var/ra...

It depends what you mean by like.

In this case, the string in $home also appears as part of $a, so in that 
sense there are alike, and the code is doing the right thing.

If you want to verify that $a and $home are identical, it would be 
easier to just check if one `eq` the other, as

print Yes - $a like $home\n if $a eq $home;

That test will work if $home is '/var/run', but will fail on '/var/ru'. 


-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: regex problem

2005-07-01 Thread Ing. Branislav Gerzo
Moon, John [MJ], on Friday, July 1, 2005 at 11:30 (-0400 ) contributed
this to our collective wisdom:

MJ I would have assumed  that /var/run would NOT be like /var/ru just as
MJ /var/run is not like /var/ra...

is /var/ru at the beginning of /var/run ? yes.

-- 

 ...m8s, cu l8r, Brano.

[If they get too annoying then we'll just have to get violent...]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: regex problem

2005-07-01 Thread Jay Savage
On 7/1/05, Moon, John [EMAIL PROTECTED] wrote:
 The following is not returning what I had expected...
 
 SUN1-BATCHperl -e '$a=q{/var/run}; $home=q{/var/123};print Yes - $a like
 $home\n if $a =~ /^$home/;'
 SUN1-BATCHperl -e '$a=q{/var/run}; $home=q{/var/ra};print Yes - $a like
 $home\n if $a =~ /^$home/;'
 SUN1-BATCHperl -e '$a=q{/var/run}; $home=q{/var/ru};print Yes - $a like
 $home\n if $a =~ /^$home/;'
 Yes - /var/run like /var/ru
 
 
 I would have assumed  that /var/run would NOT be like /var/ru just as
 /var/run is not like /var/ra...
 
 John W Moon
 

John

A regex match checks to see if the specified pattern appears in the
specified string. And the answer to the question is /var/ru in
/var/run? is yes. Or to put it another way:

   $a =~ /$home/

is functionally (although not proceedurally) equivalent to:

   $a =~ /^.*$home.*$/

If you want to do a simple test for equality, use 'eq'. If you're
going to test for a pattern and want to match on the entire string,
anchor the patern at the beginning and end of the string:

   $a =~ /^$home$/

but if $home is a simple string without regex metacharaters 'eq' it
going to be a lot faster than m//.

HTH,

-- jay

daggerquill [at] gmail [dot] com
http://www.tuaw.com
http://www.dpguru.com
http://www.engatiki.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: regex problem

2004-08-10 Thread DBSMITH
cool thanks I guess I am a wanna be programmer but do UNIX in real 
life.
So Data::Dumper shows me a structure of any scaler?  Could you show me an 
example?

thank you, 

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams






Charles K. Clarkson [EMAIL PROTECTED]
08/09/2004 06:31 PM

 
To: [EMAIL PROTECTED]
cc: [EMAIL PROTECTED]
Subject:RE: regex problem


[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote:

: it is a system app call that populates the
: $EDM_nonactive_tapelist I am not sure what you mean
: I'm not sure. has the Orig strings in it is not a
: precise statement for a computer programmer.


I meant that has the Orig strings in it does not
tell us how the strings are represented. It does not
precisely define how the data is structured.


That statement does not accurately describe the
data. Here are two examples of strings listed in a
scalar. In both cases I could describe each of these
examples as a scalar variable with strings in it.

$baz = [
[ 'foo' ],
[ 'bar' ],
];

$baz = foo\nbar\n;

As computer programmers, we have to describe
data precisely. If you are uncertain how to describe
a structure try printing it with DATA::Dumper.


: the foreach with the split did work!

Great. I'm glad I could help.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328





RE: regex problem

2004-08-10 Thread Chris Devers
On Tue, 10 Aug 2004 [EMAIL PROTECTED] wrote:
So Data::Dumper shows me a structure of any scaler?  Could you show me 
an example?
Data::Dumper is a tool for showing the structure of *any* data.
As is often the case, the perldoc has some of the best documentation:
perldoc Data::Dumper
It starts out with this:
NAME
   Data::Dumper - stringified perl data structures, suitable
   for both printing and eval
SYNOPSIS
   use Data::Dumper;
   # simple procedural interface
   print Dumper($foo, $bar);
   # extended usage with names
   print Data::Dumper-Dump([$foo, $bar], [qw(foo *ary)]);
   # configuration variables
   {
 local $Data::Dumper::Purity = 1;
 eval Data::Dumper-Dump([$foo, $bar], [qw(foo *ary)]);
   }
   # OO usage
   $d = Data::Dumper-new([$foo, $bar], [qw(foo *ary)]);
  ...
   print $d-Dump;
  ...
   $d-Purity(1)-Terse(1)-Deepcopy(1);
   eval $d-Dump;
And goes on to describe usage details  more examples.
Good luck with it!

--
Chris Devers
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: regex problem

2004-08-09 Thread Gunnar Hjalmarsson
[EMAIL PROTECTED] wrote:
All I am getting the error from my if statement:
^* matches null string many times in regex; marked by
-- HERE in m/^* -- HERE Orig/ at .
I am trying to get everything except *Orig in this output :
samlpe data snipped
Here is my code:
 
foreach ($EDM_nonactive_tapelist) {
if ($EDM_nonactive_tapelist !~ \^\*Orig) {
print $_;
}
}
- The ^ character shall not be escaped when marking the beginning of a 
string.

- You need to tell Perl that you want to use the m// operator, either like
m^\*Orig
or by using straight slashes:
/^\*Orig/
But why use a regex at all?
print unless substr($_, 0, 5) eq '*Orig';
*NOTE the variable $EDM_nonactive_tapelist has the Orig strings in it.
Does foreach read line by line?
Not unless you tell Perl so:
foreach ( split /\n/, $EDM_nonactive_tapelist ) {
print $_\n unless substr($_, 0, 5) eq '*Orig';
}
Do I even need the foreach statement?
No.
print map $_\n, grep { substr($_, 0, 5) ne '*Orig' }
  $EDM_nonactive_tapelist =~ /(.+)/mg;
;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: regex problem

2004-08-09 Thread DBSMITH
I am still getting the same error with your suggestion.  Does foreach read 
line by line?  Do I need the foreach? 

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145





Felix Li [EMAIL PROTECTED]
08/09/2004 03:56 PM

 
To: [EMAIL PROTECTED]
cc: 
Subject:Re: regex problem


perhaps you meant ^\* ... rather than \^\* ...

the later will trap things beginning with ^* ...

- Original Message - 
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, August 09, 2004 3:54 PM
Subject: regex problem


 All I am getting the error from my if statement:

 ^* matches null string many times in regex; marked by -- HERE in m/^* 
-- 
 HERE Orig/ at .

 I am trying to get everything except *Orig in this output :

 *Orig Vol: 1703FBBDED58D4AD (E00117), Seq #: 000114 in TLU: 
st_9840_acs_0,
 media: STK 984e
  Orig Vol: 0303E68522777483 (E00486), Seq #: 000800 in TLU: 
st_9840_acs_0,
 media: STK 984e

 07/12/2004 18:13:17 Rotation ID:4A03CC27.A30DEE72.0200.0E0B8707, 5
 backups
  Media duplication is not enabled.

 *Orig Vol: 4A03CC27A30DEE72 (E00632), Seq #: 000273 in TLU: 
st_9840_acs_0,
 media: STK 984e

 Here is my code:

 foreach ($EDM_nonactive_tapelist) {
 if ($EDM_nonactive_tapelist !~ \^\*Orig) {
 print $_;
 }
 }

 *NOTE the variable $EDM_nonactive_tapelist has the Orig strings in it.
 Does foreach read line by line?
 Do I even need the foreach statement?

 thank you!

 Derek B. Smith
 OhioHealth IT
 UNIX / TSM / EDM Teams







RE: regex problem

2004-08-09 Thread Charles K. Clarkson
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

: All I am getting the error from my if statement:
: 
: ^* matches null string many times in regex; marked by --
: HERE in m/^* --
: HERE Orig/ at .
: 
: I am trying to get everything except *Orig in this output :
: 
: *Orig Vol: 1703FBBDED58D4AD (E00117), Seq #: 000114 in TLU:
: st_9840_acs_0, media: STK 984e
:  Orig Vol: 0303E68522777483 (E00486), Seq #: 000800 in TLU:
: st_9840_acs_0, media: STK 984e
: 
: 07/12/2004 18:13:17 Rotation
: ID:4A03CC27.A30DEE72.0200.0E0B8707, 5
: backups
:  Media duplication is not enabled.
: 
: *Orig Vol: 4A03CC27A30DEE72 (E00632), Seq #: 000273 in TLU:
: st_9840_acs_0, media: STK 984e
: 
: Here is my code:
: 
: foreach ($EDM_nonactive_tapelist) {
: if ($EDM_nonactive_tapelist !~ \^\*Orig) {
: print $_;
: }
: }
: 
: *NOTE the variable $EDM_nonactive_tapelist has the Orig strings
: in it. Does foreach read line by line?

No. 'foreach' as used above aliases $_ to each element
of a list of scalars one item at a time. The function does
not know the concept of line.

You have provided a list of one scalar -
$EDM_nonactive_tapelist. The loop will process
$EDM_nonactive_tapelist once and place it's value in $_.
Any changes to $_ will also change $EDM_nonactive_tapelist.

Assuming $EDM_nonactive_tapelist has a list of strings
separated by newlines (\n), a list of those strings
might be expressed as this.

foreach my $srting ( split /\n/, $EDM_nonactive_tapelist ) {
print $srting\n if /^\*Orig/;
}

   In this example we have taken each string and placed it
in a scalar variable named $string. $string is tested and
printed if that test is true. The 'split' splits each
string at the newline and discard that character.


: Do I even need the foreach statement?

I'm not sure. has the Orig strings in it is not a
precise statement for a computer programmer.


Question: How did this list of strings get into a
  single scalar?



HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: regex problem

2004-08-09 Thread DBSMITH
it is a system app call that  populates the $EDM_nonactive_tapelist
I am not sure what you meanI'm not sure. has the Orig strings in it is not a
precise statement for a computer programmer.


the variable $EDM_nonactive_tapelist which is a file with the Orig strings in it !

the foreach with the split did work!

thanks!

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams






Charles K. Clarkson [EMAIL PROTECTED]
08/09/2004 05:41 PM

 
To: [EMAIL PROTECTED], [EMAIL PROTECTED]
cc: 
Subject:RE: regex problem


[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

: All I am getting the error from my if statement:
: 
: ^* matches null string many times in regex; marked by --
: HERE in m/^* --
: HERE Orig/ at .
: 
: I am trying to get everything except *Orig in this output :
: 
: *Orig Vol: 1703FBBDED58D4AD (E00117), Seq #: 000114 in TLU:
: st_9840_acs_0, media: STK 984e
:  Orig Vol: 0303E68522777483 (E00486), Seq #: 000800 in TLU:
: st_9840_acs_0, media: STK 984e
: 
: 07/12/2004 18:13:17 Rotation
: ID:4A03CC27.A30DEE72.0200.0E0B8707, 5
: backups
:  Media duplication is not enabled.
: 
: *Orig Vol: 4A03CC27A30DEE72 (E00632), Seq #: 000273 in TLU:
: st_9840_acs_0, media: STK 984e
: 
: Here is my code:
: 
: foreach ($EDM_nonactive_tapelist) {
: if ($EDM_nonactive_tapelist !~ \^\*Orig) {
: print $_;
: }
: }
: 
: *NOTE the variable $EDM_nonactive_tapelist has the Orig strings
: in it. Does foreach read line by line?

No. 'foreach' as used above aliases $_ to each element
of a list of scalars one item at a time. The function does
not know the concept of line.

You have provided a list of one scalar -
$EDM_nonactive_tapelist. The loop will process
$EDM_nonactive_tapelist once and place it's value in $_.
Any changes to $_ will also change $EDM_nonactive_tapelist.

Assuming $EDM_nonactive_tapelist has a list of strings
separated by newlines (\n), a list of those strings
might be expressed as this.

foreach my $srting ( split /\n/, $EDM_nonactive_tapelist ) {
print $srting\n if /^\*Orig/;
}

   In this example we have taken each string and placed it
in a scalar variable named $string. $string is tested and
printed if that test is true. The 'split' splits each
string at the newline and discard that character.


: Do I even need the foreach statement?

I'm not sure. has the Orig strings in it is not a
precise statement for a computer programmer.


Question: How did this list of strings get into a
  single scalar?



HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328





RE: regex problem

2004-08-09 Thread Charles K. Clarkson
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote:

: it is a system app call that populates the
: $EDM_nonactive_tapelist I am not sure what you mean
: I'm not sure. has the Orig strings in it is not a
: precise statement for a computer programmer.


I meant that has the Orig strings in it does not
tell us how the strings are represented. It does not
precisely define how the data is structured.


That statement does not accurately describe the
data. Here are two examples of strings listed in a
scalar. In both cases I could describe each of these
examples as a scalar variable with strings in it.

$baz = [
[ 'foo' ],
[ 'bar' ],
];

$baz = foo\nbar\n;

As computer programmers, we have to describe
data precisely. If you are uncertain how to describe
a structure try printing it with DATA::Dumper.


: the foreach with the split did work!

Great. I'm glad I could help.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: REGEX PROBLEM

2003-07-25 Thread Kino
On Friday, Jul 25, 2003, at 18:09 Asia/Tokyo, [EMAIL PROTECTED] 
wrote:

/tmp/test/.test.txt
/tmp/test/hallo.txt
/tmp/test/xyz/abc.txt
/var/log/ksy/123.log
now i need a regex that matches all lines but the one that contains a
filename starting with a point. like .test.txt. how can i do that?
this is what i have:

'\.(?!tgz)[^.]*$' this matches everything, but tgz at the end of a
line, so
'(?!\.)[^.]*$' should do the job, but it doesnt:(
because your expression matches, for example, just 'txt' too. Try

	/\/[^.\/][^\/]+$/g;

or

	/^.+\/[^.\/][^\/]+$/g;



Kino

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: REGEX PROBLEM

2003-07-25 Thread Rob Dixon

[EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 hi, i have the follwing strings:


 /tmp/test/.test.txt
 /tmp/test/hallo.txt
 /tmp/test/xyz/abc.txt
 /var/log/ksy/123.log


 now i need a regex that matches all lines but the one that contains a
 filename starting with a point. like .test.txt. how can i do that?

 this is what i have:

 '\.(?!tgz)[^.]*$' this matches everything, but tgz at the end of a
 line, so

 '(?!\.)[^.]*$' should do the job, but it doesnt:(

The following will help. It first generatest the file's basename in $1 by
capturing the string of all trailing characters which aren't '/', and then
checks to ensure
that that basename doesn't start with a dot..

HTH,

Rob


  while (DATA) {
chomp;
if ( m([^/]*)$ and $1 =~ /^[^.]/ ) {
  print $_, \n;
}
  }
  __DATA__
  /tmp/test/.test.txt
  /tmp/test/hallo.txt
  /tmp/test/xyz/abc.txt
  /var/log/ksy/123.log

OUTPUT

  /tmp/test/hallo.txt
  /tmp/test/xyz/abc.txt
  /var/log/ksy/123.log



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: REGEX PROBLEM (fwd)

2003-07-25 Thread magelord
---BeginMessage---
Hi
A way to solve your problem is to use the FILE module and take the filename
out using basename.
I think BaseName.pm can be downloaded form CPAN.
Please try the following:

use File::Basename;
@filenames = qw (/tmp/test/.test.txt /tmp/test/hallo.txt
/tmp/test/xyz/abc.txt /var/log/ksy/123.log);
foreach $files (@filenames)
{


if ((basename $files) !~ /^\./)
{
print (basename $files);
}
}


Thankyou
VENU

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Friday, July 25, 2003 2:39 PM
To: [EMAIL PROTECTED]
Subject: REGEX PROBLEM


hi, i have the follwing strings:


/tmp/test/.test.txt
/tmp/test/hallo.txt
/tmp/test/xyz/abc.txt
/var/log/ksy/123.log


now i need a regex that matches all lines but the one that contains a
filename starting with a point. like .test.txt. how can i do that?

this is what i have:

'\.(?!tgz)[^.]*$' this matches everything, but tgz at the end of a
line, so

'(?!\.)[^.]*$' should do the job, but it doesnt:(


THANK YOU:)

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---End Message---
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Re: regex problem

2003-07-24 Thread Sudarshan Raghavan
awarsd wrote:

Hi,

I have a number $page = 500;
now i want to check that if $page matches a word character then make $page
=1;
so originally i did this
my $page =500;
if(($page =~ /\w/) || ($page = 0)){
$page=1;
}
print$page;
since it always returns $page = 1; then i did this
if(($page =~ /(\w)/) || ($page = 0)){
$page=$1;
}
so it displayed the word 5, how come 5 is considered as a word??
perldoc perlre
\w is alphanumeric plus '_', i.e. [a-zA-Z0-9_]
so to fix it i just did
if(($page =~ /(\D)/) || ($page = 0)){
$page=$1;
}
And everything worked ok!!

any help is appreciated



 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: regex problem

2003-07-24 Thread LI NGOK LAM

 I have a number $page = 500;
 now i want to check that if $page matches a word character then make $page
 =1;

$page = 1 unless ( $page =~ /\d/ );
or
$page = 1 if ($page =~ /\D/ );


 so originally i did this
 my $page =500;
 if(($page =~ /\w/) || ($page = 0)){
 $page=1;
 }
 print$page;

\w means [a-zA-Z0-9], 5 is one of them.


 since it always returns $page = 1; then i did this
 if(($page =~ /(\w)/) || ($page = 0)){
 $page=$1;
 }
 so it displayed the word 5, how come 5 is considered as a word??

Since in string 500, the regex catch 5 as a word at the very first,
and the regex action is ended and so $1 carries 5. You then assing
$page =  $1, so $page = 5;


 so to fix it i just did
 if(($page =~ /(\D)/) || ($page = 0)){
 $page=$1;
 }
 And everything worked ok!!

It doesn't ok... since \D means [^0-9], so the block doesn't
run at all, so $page still = 500 So, if $page = END, then,
you will fine $page = E after this block.

Note : The $DIGIT means the sequence for results from catching
matched pattern in the blankets you assigned. It means, $1 is the
first match , $2 is the second match, and so on...

$page = 500;

$page =~ /(\d)(\d)(\d)/;
$page = $3 . $1;
print $page ; # you got 05, the last and first digit...

HTH




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Regex problem

2003-07-20 Thread Wiggins d'Anconia
 Sara wrote:
$name = SARA DEILEY;

how its possible to grasp only initials for First and Last name i.e $name =SD??

Depends on how standardized your data is, something simple like this 
should work for the above:

my $name = 'SARA DEILEY';
my $initials;
if ($name =~ /^(\w)\w*\s+(\w)\w*/) {
$initials = $1 . $2;
print Initials: $initials\n;
}
else {
die Can't determine initials: $name;
}
But this presents a number of problems, for instance people with 2 
first names, and you will have to decide what to do with names like 
McDonald, or if your data can be entered by humans, what if someone 
enters:  Deiley, Sara, etc.

You might also consider using 'split' and 'substr' instead of using a regex.

Either way you need to provide more info about your possible data set 
range if the above is not sufficient.

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: Regex problem

2003-07-20 Thread Scot Robnett
This is similar to Wiggins, except it checks to make sure that

A. We have a two word sequence
B. We don't have a comma

These are still very basic levels of processing, though - Wiggins is right that we 
would need to see a more thorough example of data ranges to know exactly what to 
offer. Tested, the results of this were that the program printed SD and exited as 
expected. Case sensitivity/insensitivity matching isn't required since \w will match 
either upper or lower case characters.

my $name = SARA DEILY;
if (($name =~ /\w+\s+\w+/) and ($name !~ /,/)) {
  chomp($name);
  if ($name =~ /^(\w{1})\w*\s+(\w{1})\w*$/) {
   my $initials = join (, $1 . $2);
   print $initials . \n;
  }
  else {
   print Something\'s wrong here: $!\n;
  }
}
else {
  # do more processing on different types of entries
  print Doh!;
  exit;
}


-Original Message-
From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED]
Sent: Sunday, July 20, 2003 7:10 PM
To: Sara
Cc: org
Subject: Re: Regex problem


  Sara wrote:
 $name = SARA DEILEY;
 
 how its possible to grasp only initials for First and Last name i.e $name =SD??
 

Depends on how standardized your data is, something simple like this 
should work for the above:

my $name = 'SARA DEILEY';
my $initials;
if ($name =~ /^(\w)\w*\s+(\w)\w*/) {
 $initials = $1 . $2;
 print Initials: $initials\n;
}
else {
 die Can't determine initials: $name;
}

But this presents a number of problems, for instance people with 2 
first names, and you will have to decide what to do with names like 
McDonald, or if your data can be entered by humans, what if someone 
enters:  Deiley, Sara, etc.

You might also consider using 'split' and 'substr' instead of using a regex.

Either way you need to provide more info about your possible data set 
range if the above is not sufficient.

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: Regex problem

2003-06-25 Thread Shishir K. Singh

Hi All -

This script:

use strict;
use warnings;

my $string = 'I love c++';
my $compare = 'some compare string';
if ($compare =~ /$string/) {
print $compare contains $string\n;
} else {
print $compare does not contain $string\n;
}

gives this error:

Nested quantifiers in regex; marked by -- HERE in m/I love c++ -- HERE /
at t.pl line 6.

It's the '+'s. I've tried escaping them '\+' but then
the regex matches on '\+'. I don't understand what is
happening.

This is occuring in a script that's manipulating
files; file names with '+'s fail on this error. Is there any
way I can fix this before I fall back to substrings and
'eq'/'ne' compares (ugh).

Aloha = Beau;

See if this works 

if ($compare =~ /\Q$string\E/) {

Shishir

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Regex problem

2003-06-25 Thread Tim Johnson

Try this:

my $string = 'I love c++';
my $compare = 'some compare string';
if ($compare =~ /\Q$string/) { #disables metacharacters until \E
print $compare contains $string\n;
} else {
print $compare does not contain $string\n;
}

-Original Message-
From: Beau E. Cox [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 25, 2003 8:23 AM
To: [EMAIL PROTECTED]
Subject: Regex problem


Hi All -

This script:

use strict;
use warnings;

my $string = 'I love c++';
my $compare = 'some compare string';
if ($compare =~ /$string/) {
print $compare contains $string\n;
} else {
print $compare does not contain $string\n;
}

gives this error:

Nested quantifiers in regex; marked by -- HERE in m/I love c++ -- HERE /
at t.pl line 6.

It's the '+'s. I've tried escaping them '\+' but then
the regex matches on '\+'. I don't understand what is
happening.

This is occuring in a script that's manipulating
files; file names with '+'s fail on this error. Is there any
way I can fix this before I fall back to substrings and
'eq'/'ne' compares (ugh).

Aloha = Beau;



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Regex problem

2003-06-25 Thread Beau E. Cox
Thanks Tim ans Shishir - Works!

Aloha = Beau;

- Original Message - 
From: Tim Johnson [EMAIL PROTECTED]
To: 'Beau E. Cox' [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Wednesday, June 25, 2003 5:30 AM
Subject: RE: Regex problem



 Try this:

 my $string = 'I love c++';
 my $compare = 'some compare string';
 if ($compare =~ /\Q$string/) { #disables metacharacters until \E
 print $compare contains $string\n;
 } else {
 print $compare does not contain $string\n;
 }

 -Original Message-
 From: Beau E. Cox [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, June 25, 2003 8:23 AM
 To: [EMAIL PROTECTED]
 Subject: Regex problem


 Hi All -

 This script:

 use strict;
 use warnings;

 my $string = 'I love c++';
 my $compare = 'some compare string';
 if ($compare =~ /$string/) {
 print $compare contains $string\n;
 } else {
 print $compare does not contain $string\n;
 }

 gives this error:

 Nested quantifiers in regex; marked by -- HERE in m/I love c++ -- HERE /
 at t.pl line 6.

 It's the '+'s. I've tried escaping them '\+' but then
 the regex matches on '\+'. I don't understand what is
 happening.

 This is occuring in a script that's manipulating
 files; file names with '+'s fail on this error. Is there any
 way I can fix this before I fall back to substrings and
 'eq'/'ne' compares (ugh).

 Aloha = Beau;



 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]

 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Regex problem

2003-06-25 Thread Jeff 'japhy' Pinyan
On Jun 25, Beau E. Cox said:

my $string = 'I love c++';
my $compare = 'some compare string';
if ($compare =~ /$string/) {
print $compare contains $string\n;
} else {
print $compare does not contain $string\n;
}

Why don't you want to use

  if (index($compare, $string)  -1) { ... }

There's no need to use the regex engine if you're absolutely NOT using
patterns.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Regex problem

2003-06-25 Thread John W. Krahn
Beau E. Cox wrote:
 
 Hi All -

Hello,

 This script:
 
 use strict;
 use warnings;
 
 my $string = 'I love c++';
 my $compare = 'some compare string';
 if ($compare =~ /$string/) {
 print $compare contains $string\n;
 } else {
 print $compare does not contain $string\n;
 }
 
 gives this error:
 
 Nested quantifiers in regex; marked by -- HERE in m/I love c++ -- HERE /
 at t.pl line 6.
 
 It's the '+'s. I've tried escaping them '\+' but then
 the regex matches on '\+'. I don't understand what is
 happening.
 
 This is occuring in a script that's manipulating
 files; file names with '+'s fail on this error. Is there any
 way I can fix this before I fall back to substrings and
 'eq'/'ne' compares (ugh).

It's obvious!  Anyone who claims to love C++ is in deep trouble.  :-)


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Regex problem

2003-06-25 Thread Derek Byrne
Newbie answer here - if you change the line 

my $string = 'I love c++';

to be

my $string = 'I love c\++';

it runs, but, you also get this output :

C:\SCRIPTS\testperl lovec.pl
some compare string does not contain I love c\++

DerekB

-Original Message-
From: John W. Krahn [mailto:[EMAIL PROTECTED]
Sent: 25 June 2003 20:03
To: [EMAIL PROTECTED]
Subject: Re: Regex problem


Beau E. Cox wrote:
 
 Hi All -

Hello,

 This script:
 
 use strict;
 use warnings;
 
 my $string = 'I love c++';
 my $compare = 'some compare string';
 if ($compare =~ /$string/) {
 print $compare contains $string\n;
 } else {
 print $compare does not contain $string\n;
 }
 
 gives this error:
 
 Nested quantifiers in regex; marked by -- HERE in m/I love c++ -- HERE /
 at t.pl line 6.
 
 It's the '+'s. I've tried escaping them '\+' but then
 the regex matches on '\+'. I don't understand what is
 happening.
 
 This is occuring in a script that's manipulating
 files; file names with '+'s fail on this error. Is there any
 way I can fix this before I fall back to substrings and
 'eq'/'ne' compares (ugh).

It's obvious!  Anyone who claims to love C++ is in deep trouble.  :-)


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Meteor web site http://www.meteor.ie



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Regex problem

2003-06-25 Thread Beau E. Cox

- Original Message - 
From: Jeff 'japhy' Pinyan [EMAIL PROTECTED]
To: Beau E. Cox [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Wednesday, June 25, 2003 8:45 AM
Subject: Re: Regex problem


 On Jun 25, Beau E. Cox said:
 
 my $string = 'I love c++';
 my $compare = 'some compare string';
 if ($compare =~ /$string/) {
 print $compare contains $string\n;
 } else {
 print $compare does not contain $string\n;
 }
 
 Why don't you want to use
 
   if (index($compare, $string)  -1) { ... }
 
 There's no need to use the regex engine if you're absolutely NOT using
 patterns.
 

Thanks Japhy -

Sometimes you get in a rut (in my case I seem to
have regexs on my brain) and don't take the time to
think of the better way to get something done. Yes,
your solution is GOOD - I'll use it.

Aloha = Beau;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: regex problem - solved

2002-10-10 Thread Gary Stainburn

Hi folks,

I've sorted it, here's the sub that I'm now using:

sub splitit {
  my ($line)=@_;
  if ($line=~/^(.*)(\D{1,2}\d{1,2}\s{0,1}\d\D{2})\s*/) {
return ($1,$2);
  } else {
return ($line,'');
  }
}

Gary

On Thursday 10 Oct 2002 2:36 pm, Gary Stainburn wrote:
 Hi all,

 I've got a variable containing the last line of a UK postal address which
 may or may not contain a postcode.  I need to remove the postcode and place
 it somewhere else and therefore think a regex of the form:

 if ($lastline=~/myregex/) {
   $lastline=$1;
   $postcode=$2;
 }

 However I'm having problems with the regex.  The criteria is:

 The postcode may or may not have anything before it (the $1 bit)
 The postcode may only have whitespace, '.' or ',' after it (which does not
 want to be kept)

 The postcode is of the format
   1 or 2 letters
   1 or 2 numbers,
   optional space
   1 number
   2 letters

 If it is only a partial postcode it will have only up to the optional
 space. However, if this cannot be catered for, it's not the end of the
 world.

 Gary

-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: regex problem

2002-10-10 Thread Janek Schleicher

Gary Stainburn wrote:

 However I'm having problems with the regex.  The criteria is:
 
 The postcode may or may not have anything before it (the $1 bit)
 The postcode may only have whitespace, '.' or ',' after it (which does not 
 want to be kept)
 
 The postcode is of the format
   1 or 2 letters
   1 or 2 numbers,
   optional space
   1 number
   2 letters
 


That can be translated 1:1 to Perl:

my $postcode_re = qr/[A-Za-z]{1,2}# 1 or 2 letters
  \d{1,2}  # 1 or 2 numbers
  \s?  # optional space
  \d   # 1 number
  [A-Za-z]{2}  # 2 letters
 /x;

So now we can build the regexp for your problem:
if ($lastline =~ /(.*)($postcode_re)[\s.,]/) {
my $stuff_before_code = $1;
my $postcode  = $2;
...
}


 If it is only a partial postcode it will have only up to the optional space.  
 However, if this cannot be catered for, it's not the end of the world.

I can't answer it,
as I don't know what a partial postcode should be (I'm not from the UK).


Best Wishes,
Janek


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Regex Problem

2002-07-31 Thread John Francis

woah...

why is $bar = \${foo} - ? something is weird there...

also the problem was with your substitution op

$bar =~ s/\$\{\(\w+)\}/\$${1}/g;

- John

On Mon, 29 Jul 2002, Balint, Jess wrote:

 Thanks. Here is what I am trying to accomplish:
 
 $foo = something;
 $bar = \${foo};
 $bar =~ s/\$\{\(\w+)\}/$$1/g;
 print $bar;
 
 OUTPUT:
 
 something
 
 I am getting an error:
 
 Can't use string (something) as a SCALAR ref while strict refs in use at
 .. . .
 Thanks.
 
 Jess
 
 -Original Message-
 From: John Francis
 To: Balint, Jess
 Cc: '[EMAIL PROTECTED]'
 Sent: 7/28/02 10:14 PM
 Subject: Re: Regex Problem
 
 Jess,
  Try:
   s/\$\{(\w+)\}/\$${1}/g;
 
  if i understood your problem correctly =)
   - John
 
 On Sun, 28 Jul 2002, Balint, Jess wrote:
 
  Hello all. I am getting an error with the following reg-exp:
  
  s/\$\{(\w+)\}/$$1/g;
  
  I am not sure exactly how to do this type of thing. Is there any way
 to get
  around the error or must I turn off 'strict refs' for this line??
 Thanks
  alot.
  
  Jess
  
  -- 
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  
  
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Regex Problem

2002-07-29 Thread Balint, Jess

Thanks. Here is what I am trying to accomplish:

$foo = something;
$bar = \${foo};
$bar =~ s/\$\{\(\w+)\}/$$1/g;
print $bar;

OUTPUT:

something

I am getting an error:

Can't use string (something) as a SCALAR ref while strict refs in use at
.. . .
Thanks.

Jess

-Original Message-
From: John Francis
To: Balint, Jess
Cc: '[EMAIL PROTECTED]'
Sent: 7/28/02 10:14 PM
Subject: Re: Regex Problem

Jess,
 Try:
s/\$\{(\w+)\}/\$${1}/g;

 if i understood your problem correctly =)
- John

On Sun, 28 Jul 2002, Balint, Jess wrote:

 Hello all. I am getting an error with the following reg-exp:
 
   s/\$\{(\w+)\}/$$1/g;
 
 I am not sure exactly how to do this type of thing. Is there any way
to get
 around the error or must I turn off 'strict refs' for this line??
Thanks
 alot.
 
 Jess
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regex Problem

2002-07-28 Thread Robin Norwood

Balint, Jess [EMAIL PROTECTED] writes:

 Hello all. I am getting an error with the following reg-exp:
 
   s/\$\{(\w+)\}/$$1/g;
 
 I am not sure exactly how to do this type of thing. Is there any way to get
 around the error or must I turn off 'strict refs' for this line?? Thanks
 alot.

I'm not exactly sure what you are trying to do here - if my suggestion
isn't what you want, please give a better description of what you want
- It looks like you want to change: '${bar}' into '$bar', so - just
escape the first '$' in the substitution part of your regexp:

#!/usr/bin/perl -lw #the 'l' adds a newline to the end of any 'print'

my $foo = '${bar}';
print $foo; 
$foo =~ s/\$\{(\w+)\}/\$$1/g;
print $foo;


OUTPUT - 

${bar}
$bar


You are getting the warning becuase $$1 is an attempt to dereference
a scalar reference called '$1'.

-RN

-- 

Robin Norwood
Red Hat, Inc.

The Sage does nothing, yet nothing remains undone.
-Lao Tzu, Te Tao Ching

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regex Problem

2002-07-28 Thread John Francis

Jess,
 Try:
s/\$\{(\w+)\}/\$${1}/g;

 if i understood your problem correctly =)
- John

On Sun, 28 Jul 2002, Balint, Jess wrote:

 Hello all. I am getting an error with the following reg-exp:
 
   s/\$\{(\w+)\}/$$1/g;
 
 I am not sure exactly how to do this type of thing. Is there any way to get
 around the error or must I turn off 'strict refs' for this line?? Thanks
 alot.
 
 Jess
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regex Problem

2002-07-28 Thread Jeff 'japhy' Pinyan

On Jul 28, Balint, Jess said:

Hello all. I am getting an error with the following reg-exp:

   s/\$\{(\w+)\}/$$1/g;

I am not sure exactly how to do this type of thing. Is there any way to get
around the error or must I turn off 'strict refs' for this line?? Thanks
alot.

If you're trying to expand variables in a string, have you looked at:

  perldoc -q variables

Anyway, I suggest something like:

  s/\${(\w+)}/\$$1/eeg;

or perhaps the simpler

  s/(\${\w+})/$1/eeg;

But it's even safer to use a hash, like the FAQ I mentioned suggests.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for Regular Expressions in Perl published by Manning, in 2002 **
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: regex - problem

2002-07-22 Thread perl-dvd

Alex,
Did you get the problem fixed?  Yes it was because you did not escape your . when 
you wanted a .
instead of an any character.

..[a-zA-Z]{2,3} will match .abc, but it will also match abcd but \.[a-zA-Z]{2,3} 
will require
that the first character this part of the regular expression matches is a period, not 
an any
character.

Regards,
David


- Original Message -
From: alex [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, July 19, 2002 10:16 AM
Subject: regex - problem


Hi,

I have this unsignificant problem:  I try to match an email-adress...
works, EXCEPT the very last .com or .de ... it matches .com and .de
but not .d nor .x - ok so far.
but it also matches .dererere - which it shouldn't. I used the {2,3}
but it seems, that the max-count is being ignored.

any ideas? thanks in advance


if (@ARGV != 1){
print ONE PARAMETER ONLY!!!\n
} else {

if ($ARGV[0] =~
/^([_a-zA-Z0-9-]+)(.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+)(.[a-zA-Z0-9-]+).[a-zA-Z]{2,3}$/){
@a = split /@/,$ARGV[0];
print user:   $a[0]\ndomain: $a[1]\n;
print MATCH\n;
}else{
print MISMATCH\n;
}

}




--
cheers
 alex  mailto:[EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Regex Problem - please help

2002-06-05 Thread Hanson, Robert

Here is my solution, others will differ...

# always print $! on error so you can see the cause
open( INFILE,books.txt ) || die Cann't Open: $!;

while( INFILE ) {
chomp; # remove the newline
next unless ($_); # skip blank lines

# split the line by the seperator
my @parts= split(/ by /, $_);

# die unless exactly 2 parts are found
die Can't split properly unless ( @parts == 2 );

print $author - $book\n;
}

close INFILE;


Rob


-Original Message-
From: Denham Eva [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 9:42 AM
To: BeginnersPerl (E-mail)
Subject: Regex Problem - please help


Hello Listers,

I am struggling to get this right. Beginner in perl, so please forgive
ignorance, but the regular expressions are confusing.

I am trying to read in a file, with content as follows
---snip---
1984 by George Orwell
A BEND IN THE RIVER by V.S. Naipaul
A CLOCKWORK ORANGE by Anthony Burgess
A DANCE TO THE MUSIC OF TIME (series) by Anthony Powell
A FAREWELL TO ARMS by Ernest Hemingway
A HANDFUL OF DUST by Evelyn Waugh
---end snip---
The idea is to list by Author ie.

George Orwell - 1984
V.S. Naipaul - A BEND IN THE RIVER 
Anthony Burgess - A CLOCKWORK ORANGE 
Anthony Powell - A DANCE TO THE MUSIC OF TIME (series) 
Ernest Hemingway - A FAREWELL TO ARMS 
Evelyn Waugh - A HANDFUL OF DUST

OK my code thus far is:-

--- Spin Code ---
open(INFILE,books.txt)||die Cann't Open;

while(INFILE) {
  $_ =~ m/[A-Fa-z0-9]/ || die Sorry Don't Work; # Here regex is for
everything
# But I would like to chop it up to divide Authors from Books
# Then to add them together with:- print $author - $Book -:for instance
# In the end to write the output to a seperate file.

  $index = $_;

  print $index;
}
--- Close Code ---
Now this produces a whole string, which I know, unfortunately I am not to
good with the regex part.

Any help will be much appreciated.

Denham Eva
Oracle DBA
In UNIX Land
On a quiet Night, you can hear the Windows machines reboot.



#
This e-mail message has been scanned for Viruses and Content and cleared 
by MailMarshal
For more information please visit www.marshalsoftware.com

#

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Regex Problem - please help

2002-06-05 Thread Janek Schleicher

Robert Hanson wrote at Wed, 05 Jun 2002 15:57:05 +0200:

 Here is my solution, others will differ...
 

Yep, if you like it short ;-)
open BOOK_LIST, books.txt or die Can't Open: $!;
print join \n, map {chomp; /(.*) by (.*)/; $2 - $1} (BOOKLIST);
close BOOK_LIST;

 # always print $! on error so you can see the cause open( INFILE,books.txt ) || 
die Cann't
 Open: $!;
 
 while( INFILE ) {
   chomp; # remove the newline
   next unless ($_); # skip blank lines
 
   # split the line by the seperator
   my @parts= split(/ by /, $_);
 
   # die unless exactly 2 parts are found
   die Can't split properly unless ( @parts == 2 );
 
   print $author - $book\n;
 }
 }
 close INFILE;


Greetings,
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Regex Problem - please help

2002-06-05 Thread Janek Schleicher

Janek Schleicher wrote at Wed, 05 Jun 2002 16:19:11 +0200:

 Yep, if you like it short ;-)
 open BOOK_LIST, books.txt or die Can't Open: $!; 
 print join \n, map {chomp; /(.*) by (.*)/; $2 - $1} (BOOKLIST); 
   ^^^
Oh a typo :-(

 close BOOK_LIST;


Cheerio,
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Thanks - Re: Regex problem extracting middle-word part of string

2002-06-05 Thread Rohesia Hamilton Metcalfe

Thanks Janek and Japhy and Drieux for all the help on this!

I've yet to look at this Tie::Pick, but will.

In the meantime, I've gone with the Japhy solution, 

   $element = @things[rand @things];

because it was the simplest (and works).

I didn't quite see why you would have to do a +1 on the following:

   my $RandomScript = $Scripts[int(rand($#Scripts + 1))];

because isn't the first element of an array (eg @array) $array[0]
anyway? Such that you'd want the numbers 0-3 for a 4-element array
rather than 1-4? (unless rand only works with numbers greater than zero
and, in Japhy's solution, is doing this implicitly?)

Still, grateful to know I can skip the srand; line. When I started
this, the first random seeding code I came across was even more typing:

   srand(time() ^ ($$ + ($$  15)) );

Well, that worked, too, but...

Anyway, again, many thanks for all,

Rohesia
 
--- Janek Schleicher [EMAIL PROTECTED] wrote:
 Rohesia Hamilton Metcalfe wrote at Thu, 30 May 2002 17:28:45 +0200:
 
  #make array of cgi-scripts:
  @Scripts=(f-.cgi, f-bb.cgi, f-.cgi, f-.cgi,
 f-ee.cgi,
  f-ff.cgi);
  
  # pick one at random
  srand;
  $RandomScript = $Scripts[int(rand(@Scripts))];
  
 
 I agree to Drieux that such a random selection looks strange.
 I always feel nervous when i see Jeff's solution.
 Not because of the underlying context what let's a floating value
 becomes an int,
 but $element = $things[rand @things] hides the real information.
 And there's double code (things), what is a real crime :-))
 
 Let's look at an existing module:
 
 use Tie::Pick;
 tie my $randomScript = Tie::Pick = @scripts;
 
 There's a disadventage, too.
 Tie::Pick removes the element chosen,
 but when it doesn't play a role or is even wanted,
 I'd suggest the above solution.
 Otherwise I'd prefer Jeff's solution.
 
 Greetings,
 Janek
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 


=
Rohesia Hamilton Metcalfe

__
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Thanks - Re: Regex problem extracting middle-word part of string

2002-06-05 Thread Felix Geerinckx

 I didn't quite see why you would have to do a +1 on the following:
 
my $RandomScript = $Scripts[int(rand($#Scripts + 1))];

The '$#array' construct returns the index of the last element of the 
'@array'. 'rand $number' returns a random number between 0 (inclusive) 
and $number (exclusive). the 'int' function throws away the fractional 
part.

If you don't add 1, you would never get the last array-element.

-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Thanks - Re: Regex problem extracting middle-word part of string

2002-06-05 Thread Nikola Janceski

shouldn't it be written as this to aviod that confusion:
my $RandomScript = $Scripts[rand(@Scripts)];


 -Original Message-
 From: Felix Geerinckx [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, June 05, 2002 11:18 AM
 To: [EMAIL PROTECTED]
 Subject: Re: Thanks - Re: Regex problem extracting middle-word part of
 string
 
 
  I didn't quite see why you would have to do a +1 on the following:
  
 my $RandomScript = $Scripts[int(rand($#Scripts + 1))];
 
 The '$#array' construct returns the index of the last element of the 
 '@array'. 'rand $number' returns a random number between 0 
 (inclusive) 
 and $number (exclusive). the 'int' function throws away the 
 fractional 
 part.
 
 If you don't add 1, you would never get the last array-element.
 
 -- 
 felix
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regex Problem - please help

2002-06-05 Thread John W. Krahn

Denham Eva wrote:
 
 Hello Listers,

Hello,

 I am struggling to get this right. Beginner in perl, so please forgive
 ignorance, but the regular expressions are confusing.
 
 I am trying to read in a file, with content as follows
 ---snip---
 1984 by George Orwell
 A BEND IN THE RIVER by V.S. Naipaul
 A CLOCKWORK ORANGE by Anthony Burgess
 A DANCE TO THE MUSIC OF TIME (series) by Anthony Powell
 A FAREWELL TO ARMS by Ernest Hemingway
 A HANDFUL OF DUST by Evelyn Waugh
 ---end snip---
 The idea is to list by Author ie.
 
 George Orwell - 1984
 V.S. Naipaul - A BEND IN THE RIVER
 Anthony Burgess - A CLOCKWORK ORANGE
 Anthony Powell - A DANCE TO THE MUSIC OF TIME (series)
 Ernest Hemingway - A FAREWELL TO ARMS
 Evelyn Waugh - A HANDFUL OF DUST
 
 OK my code thus far is:-
 
 --- Spin Code ---
 open(INFILE,books.txt)||die Cann't Open;
 
 while(INFILE) {
   $_ =~ m/[A-Fa-z0-9]/ || die Sorry Don't Work; # Here regex is for
 everything
 # But I would like to chop it up to divide Authors from Books
 # Then to add them together with:- print $author - $Book -:for instance
 # In the end to write the output to a seperate file.
 
   $index = $_;
 
   print $index;
 }
 --- Close Code ---


open INFILE, 'books.txt' or die Cannot open 'books.txt': $!;

while ( INFILE ) {
chomp;
s/(.+?)\s+by\s+(.+)/$2 - $1/
print $_\n;
}



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Regex Problem - please help

2002-06-05 Thread David . Wagner

With the solutions presented, I used rindex since what about the
title: 'Perl by example by New Author' . Doing a split and you will not have
what you expected.  Here is a shot:


while ( DATA ) {
chomp;
next if ( /^\s*$/ );
my $MyPtr = rindex($_, by );

if ( $MyPtr  0 ) {
   printf Expecting a title followed \' by \' Author.  Data:\n;
   printf %-s\n, $_;
   next;
 }
my $MyTitle  = substr($_,0,$MyPtr);
my $MyAuthor = substr($_,($MyPtr+4));
printf %-s - %-s\n, $MyAuthor, $MyTitle;
 }
__DATA__
1984 by George Orwell
A BEND IN THE RIVER by V.S. Naipaul
A CLOCKWORK ORANGE by Anthony Burgess
A DANCE TO THE MUSIC OF TIME (series) by Anthony Powell
A FAREWELL TO ARMS by Ernest Hemingway
A HANDFUL OF DUST by Evelyn Waugh

Output: 

George Orwell - 1984
V.S. Naipaul - A BEND IN THE RIVER
Anthony Burgess - A CLOCKWORK ORANGE
Anthony Powell - A DANCE TO THE MUSIC OF TIME (series)
Ernest Hemingway - A FAREWELL TO ARMS
Evelyn Waugh - A HANDFUL OF DUST
New Author - Perl by example

Wags ;)
-Original Message-
From: Hanson, Robert [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 06:57
To: 'Denham Eva'; BeginnersPerl (E-mail)
Subject: RE: Regex Problem - please help


Here is my solution, others will differ...

# always print $! on error so you can see the cause
open( INFILE,books.txt ) || die Cann't Open: $!;

while( INFILE ) {
chomp; # remove the newline
next unless ($_); # skip blank lines

# split the line by the seperator
my @parts= split(/ by /, $_);

# die unless exactly 2 parts are found
die Can't split properly unless ( @parts == 2 );

print $author - $book\n;
}

close INFILE;


Rob


-Original Message-
From: Denham Eva [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 9:42 AM
To: BeginnersPerl (E-mail)
Subject: Regex Problem - please help


Hello Listers,

I am struggling to get this right. Beginner in perl, so please forgive
ignorance, but the regular expressions are confusing.

I am trying to read in a file, with content as follows
---snip---
1984 by George Orwell
A BEND IN THE RIVER by V.S. Naipaul
A CLOCKWORK ORANGE by Anthony Burgess
A DANCE TO THE MUSIC OF TIME (series) by Anthony Powell
A FAREWELL TO ARMS by Ernest Hemingway
A HANDFUL OF DUST by Evelyn Waugh
---end snip---
The idea is to list by Author ie.

George Orwell - 1984
V.S. Naipaul - A BEND IN THE RIVER 
Anthony Burgess - A CLOCKWORK ORANGE 
Anthony Powell - A DANCE TO THE MUSIC OF TIME (series) 
Ernest Hemingway - A FAREWELL TO ARMS 
Evelyn Waugh - A HANDFUL OF DUST

OK my code thus far is:-

--- Spin Code ---
open(INFILE,books.txt)||die Cann't Open;

while(INFILE) {
  $_ =~ m/[A-Fa-z0-9]/ || die Sorry Don't Work; # Here regex is for
everything
# But I would like to chop it up to divide Authors from Books
# Then to add them together with:- print $author - $Book -:for instance
# In the end to write the output to a seperate file.

  $index = $_;

  print $index;
}
--- Close Code ---
Now this produces a whole string, which I know, unfortunately I am not to
good with the regex part.

Any help will be much appreciated.

Denham Eva
Oracle DBA
In UNIX Land
On a quiet Night, you can hear the Windows machines reboot.



#
This e-mail message has been scanned for Viruses and Content and cleared 
by MailMarshal
For more information please visit www.marshalsoftware.com

#

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Thanks - Re: Regex problem extracting middle-word part of str ing

2002-06-05 Thread Felix Geerinckx

on Wed, 05 Jun 2002 15:26:12 GMT, Nikola Janceski wrote:

 shouldn't it be written as this to aviod that confusion:
 my $RandomScript = $Scripts[rand(@Scripts)];
 

Yes, that's also my preferred way.

-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Regex Problem - please help

2002-06-05 Thread Denham Eva

Thank You - all that have supplied me with a solution to the problem below.
I am amazed once again at the power of perl, I had imagined pages of code
and what do I receive? five line solutions! Absolutely Amazing.
My resolve has been strengthened to learn perl even more.
Thanks.

-Original Message-
From: Denham Eva [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 3:42 PM
To: BeginnersPerl (E-mail)
Subject: Regex Problem - please help


Hello Listers,

I am struggling to get this right. Beginner in perl, so please forgive
ignorance, but the regular expressions are confusing.

I am trying to read in a file, with content as follows
---snip---
1984 by George Orwell
A BEND IN THE RIVER by V.S. Naipaul
A CLOCKWORK ORANGE by Anthony Burgess
A DANCE TO THE MUSIC OF TIME (series) by Anthony Powell
A FAREWELL TO ARMS by Ernest Hemingway
A HANDFUL OF DUST by Evelyn Waugh
---end snip---
The idea is to list by Author ie.

George Orwell - 1984
V.S. Naipaul - A BEND IN THE RIVER 
Anthony Burgess - A CLOCKWORK ORANGE 
Anthony Powell - A DANCE TO THE MUSIC OF TIME (series) 
Ernest Hemingway - A FAREWELL TO ARMS 
Evelyn Waugh - A HANDFUL OF DUST

OK my code thus far is:-

--- Spin Code ---
open(INFILE,books.txt)||die Cann't Open;

while(INFILE) {
  $_ =~ m/[A-Fa-z0-9]/ || die Sorry Don't Work; # Here regex is for
everything
# But I would like to chop it up to divide Authors from Books
# Then to add them together with:- print $author - $Book -:for instance
# In the end to write the output to a seperate file.

  $index = $_;

  print $index;
}
--- Close Code ---
Now this produces a whole string, which I know, unfortunately I am not to
good with the regex part.

Any help will be much appreciated.

Denham Eva
Oracle DBA
In UNIX Land
On a quiet Night, you can hear the Windows machines reboot.



#
This e-mail message has been scanned for Viruses and Content and cleared 
by MailMarshal
For more information please visit www.marshalsoftware.com

#

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

#
This e-mail message has been scanned for Viruses and Content and cleared 
by MailMarshal
For more information please visit www.marshalsoftware.com
#

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regex problem extracting middle-word part of string

2002-06-04 Thread Janek Schleicher

Rohesia Hamilton Metcalfe wrote at Thu, 30 May 2002 17:28:45 +0200:

 #make array of cgi-scripts:
 @Scripts=(f-.cgi, f-bb.cgi, f-.cgi, f-.cgi, f-ee.cgi,
 f-ff.cgi);
 
 # pick one at random
 srand;
 $RandomScript = $Scripts[int(rand(@Scripts))];
 

I agree to Drieux that such a random selection looks strange.
I always feel nervous when i see Jeff's solution.
Not because of the underlying context what let's a floating value becomes an int,
but $element = $things[rand @things] hides the real information.
And there's double code (things), what is a real crime :-))

Let's look at an existing module:

use Tie::Pick;
tie my $randomScript = Tie::Pick = @scripts;

There's a disadventage, too.
Tie::Pick removes the element chosen,
but when it doesn't play a role or is even wanted,
I'd suggest the above solution.
Otherwise I'd prefer Jeff's solution.

Greetings,
Janek


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Regex Problem!!- SOS

2002-05-31 Thread David Gray

 if ($var =~ /^$var1/) {

 if($var =~ /^\Q$var1\E/) {

Should solve your problem -- the \Q and \E tell the regex to stop (and
start again) interpolating any regex characters it finds in the
variable.

HTH,

 -dave



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Regex Problem!!- SOS

2002-05-31 Thread Shishir K. Singh

Thanks a lot Dave!!

-Original Message-
From: David Gray [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 31, 2002 2:45 PM
To: [EMAIL PROTECTED]
Cc: Shishir K. Singh
Subject: RE: Regex Problem!!- SOS


 if ($var =~ /^$var1/) {

 if($var =~ /^\Q$var1\E/) {

Should solve your problem -- the \Q and \E tell the regex to stop (and
start again) interpolating any regex characters it finds in the
variable.

HTH,

 -dave



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regex problem extracting middle-word part of string

2002-05-30 Thread Jeff 'japhy' Pinyan

On May 30, drieux said:

 srand;
 $RandomScript = $Scripts[int(rand(@Scripts))];

   my $RandomScript = $Scripts[int(rand($#Scripts + 1))];

I am also a bit concerned with trying to seed rand() with a
list, rather than say, the count of the list as noted above.

never be afraid to step aside, whip out a silly bit in YourTmpDirHere
and bash the semantics till it does what you really want...
since you do recall that it provides for a random value
from 0 to less than expr - hence you want (index + 1) so
that you can get your last element in the list

Don't worry.  rand() requires its argument to be a scalar, so rand(@x) is
like rand(scalar @x) (which is for all intents and purposes rand($#x+1)).

I'm more concerned about the use of srand(), which is superfluous in
recent Perls.  The int() is also superfluous.

  $element = @things[rand @things];

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for Regular Expressions in Perl published by Manning, in 2002 **
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regex problem extracting middle-word part of string

2002-05-30 Thread drieux


On Thursday, May 30, 2002, at 08:28 , Rohesia Hamilton Metcalfe wrote:
[..]

 Any help much appreciated.

 Rohesia

perlsonally I'm a fore and aft fan and would have done it like

my $fore = 'f-';
my $aft = '.cgi';

my $ScriptName = $1 if ($RandomScript =~ /$fore # all the stuff before 
it
  (.*)  # $1 - 
the stuff we want
  $aft/xo); # all 
the stuff aft of it

print foreand aft says :$RandomScript: undt :$ScriptName:\n;

which will be more 're-usable' in the long run, and
of course has the if check as welll...

ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regex problem extracting middle-word part of string

2002-05-30 Thread drieux


On Thursday, May 30, 2002, at 11:13 , Jeff 'japhy' Pinyan wrote:

 On May 30, drieux said:

 srand;
 $RandomScript = $Scripts[int(rand(@Scripts))];

  my $RandomScript = $Scripts[int(rand($#Scripts + 1))];
[..]
 Don't worry.  rand() requires its argument to be a scalar, so rand(@x) is
 like rand(scalar @x) (which is for all intents and purposes rand($#x+1)).

 I'm more concerned about the use of srand(), which is superfluous in
 recent Perls.  The int() is also superfluous.

good to hear that we do not have to go back quite to the perl4 tricks.


   $element = @things[rand @things];

that works - but it makes me nervous...

http://www.wetware.com/drieux/pbl/perlTrick/randPick.txt



ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regex problem extracting middle-word part of string

2002-05-30 Thread drieux


On Thursday, May 30, 2002, at 11:44 , Jeff 'japhy' Pinyan wrote:
 On May 30, drieux said:

   $element = @things[rand @things];

 that works - but it makes me nervous...

 You've no need to feel uneasy.  It doesn't work because of cruftiness --

I was perchance not clear - I had been doing stuff that
way for, well a long time not that this is crufty

it still makes me nervous... these newFangledThings and all

 it's merely combining known facts about how Perl operates:

   1. rand() expects a scalar
   2. array indices are integers

 In fact, the Perl FAQ does it this way (albeit in two steps):

   $index   = rand @array;
   $element = $array[$index];

that I expect - and would have used up until your kvetch,
the first step foward was to skip the $index - you know
'chance it' this whole 'lisp' style of coding

Oh I see, now I get where we slipped the disk

srand was required up to 5.004

and there is your FAQ

How do I select a random element from an array?

with the

$element = $thing[rand @thing];

as I originally coded it.

ciao
drieux

---

That's the problem with kids these days,
no respect for their elders
why when we were growing up we had 'the doors'


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regex problem?

2002-01-13 Thread Ahmed Moustafa

Hi Troy,

I don't understand your regex. I think the following should work fine:

$message =~ s/(;-\)|;\))/img src=$cfg{'nonCgiPath'}\/wink.gif\/g;

Regards,
--Ahmed
[EMAIL PROTECTED] | http://www.photo.net/users/ahmed


Troy May wrote:

 Hello,
 
 I'm having a problem with a bulletin board I'm setting up.  All the smilies
 work except for one, the wink one.  which be called when you type in ;).
 It won't display the graphic.  All the others are fine so I know's it not a
 config or directory problem.  Here's the regex that looks for it:
 
 $message =~ s/(\W|\A)\;\-\)/$1\img src=$cfg{'nonCgiPath'}\/wink.gif\/g;
 
 Am I missing something here?
 
 Thanks in advance.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regex problem?

2002-01-13 Thread Curtis Poe

--- Troy May [EMAIL PROTECTED] wrote:
 Hello,
 
 I'm having a problem with a bulletin board I'm setting up.  All the smilies
 work except for one, the wink one.  which be called when you type in ;).
 It won't display the graphic.  All the others are fine so I know's it not a
 config or directory problem.  Here's the regex that looks for it:
 
 $message =~ s/(\W|\A)\;\-\)/$1\img src=$cfg{'nonCgiPath'}\/wink.gif\/g;
 
 Am I missing something here?
 
 Thanks in advance.

Hi Troy,

Assuming that you want to match both ';)' and ';-)', you can do this:

$message =~ s/(;-?\))/$1img src=cfg{'nonCgiPath'}\/wink.gif/g;

Note that I have deliberately wrapped the attribute value in quotes.  This is the 
proper way to
handle HTML and can stop a lot of problems later on.

Cheers,
Curtis Ovid Poe

=
Ovid on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//;
shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A

__
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Regex problem?

2002-01-13 Thread Jeff 'japhy' Pinyan

On Jan 13, Troy May said:

I'm having a problem with a bulletin board I'm setting up.  All the smilies
work except for one, the wink one.  which be called when you type in ;).
It won't display the graphic.  All the others are fine so I know's it not a
config or directory problem.  Here's the regex that looks for it:

$message =~ s/(\W|\A)\;\-\)/$1\img src=$cfg{'nonCgiPath'}\/wink.gif\/g;

You have it written to match ;-) not ;).  Remove the \- from the regex.

And the character ; -   are not special to regexes.  And if you don't
want to write \/ in a regex to have a / in it, you can use a different
regex delimiter:

  $message =~ s{(?!\w);\)}{img src=$cfg{nonCgiPath}/wink.gif}g;

I also changed your (\W|\A) to (?!\w) which matches the same way, but
doesn't actually CONSUME what it matched -- that's why I don't have $1 on
the right-hand side.

(?!\w) means not preceded by a word character, which is the same as
your (\W|\A) which means non-word character or beginning of string.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for Regular Expressions in Perl published by Manning, in 2002 **
stu what does y/// stand for?  tenderpuss why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: regex problem

2001-12-04 Thread Jeff 'japhy' Pinyan

On Dec 5, Rahul Garg said:

how to check $line contains how many tabs ..is there any func in perl

You might want to use the tr/// operator.

  $tab_count = ($string =~ tr/\t//);
  if ($tab_count == 1) {
# ...
  }

Or, more briefly:

  if (($string =~ tr/\t//) == 1) {
# ...
  }

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for Regular Expressions in Perl published by Manning, in 2002 **


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: regex problem

2001-11-12 Thread Garry Williams

On Mon, Nov 12, 2001 at 07:14:42PM -0600, Gibbs Tanton - tgibbs wrote:
 Seems like to me you should just change the last capture to be [^\n] as in
 
 $data =~ /http:\/\/(.*?):(.*?)@([^\n]*?)/g; 
 
 or something like that.

I haven't followed the whole thread, but `[^\n]' is exactly the same
as `.' as long as /s is *not* specified.  

-- 
Garry Williams, Zvolve Systems, Inc., +1 770 551-4504

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: regex problem

2001-07-24 Thread Neema Salimi

Left off a damn parenthesis, it's been a long day.  Sorry.

Neema Salimi
[EMAIL PROTECTED]



Re: regex problem

2001-07-24 Thread Paul


--- Neema Salimi [EMAIL PROTECTED] wrote:
I know you've already solved this on your own, but just a small note:

 if ($_ =~ /CA\s*ARG\s*1\s*(-*\d+\.\d+)\s*(-*\d+\.\d+)\s*(-*\d+\.\d+)/


the $_ =~ is unnecessary.
The match operator defaults to matching $_,
so saying 

   /foo/

is exactly equivelent to saying

  $_ =~ m/foo/

but with less line-noise. =o)



__
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Regex Problem

2001-06-21 Thread John Edwards

if ($cur_sym) {
printf OUTFILE %s\,%s\,%s\,%s\,%s\,%s\,%s\n,$date, $time, $tz,
$cur_sym, $cur_desc, $usd_unit, $units_usd;
}

-Original Message-
From: Jack Lauman [mailto:[EMAIL PROTECTED]]
Sent: 21 June 2001 17:15
To: [EMAIL PROTECTED]
Subject: Regex Problem


I get the following results when running the perl script below.  For
some reason I get (3) lines that don't match the regex criteria before
it reaches the first line that has data, and one additional line after
the script completes.  Is there a way to not write the line if the 
varaiable $cur_sym is empty?

Thanks in advance,

Jack

Output from script:

2000-12-29,16:16:19,PST
2000-12-29,16:16:19,PST
2000-12-29,16:16:19,PST
2000-12-29,16:16:19,PST,USD,United States Dollars   ,1.0,1.0
2000-12-29,16:16:19,PST,EUR,Euro   
,0.941604,1.06202
2000-12-29,16:16:19,PST,GBP,United Kingdom Pounds  
,1.49242,0.670052
2000-12-29,16:16:19,PST,CAD,Canada Dollars 
,0.666790,1.49972
2000-12-29,16:16:19,PST,DEM,Germany Deutsche Marks 
,0.481435,2.07712
2000-12-29,16:16:19,PST,FRF,France Francs  
,0.143547,6.96638
2000-12-29,16:16:19,PST,JPY,Japan Yen  
,0.00872554,114.606
2000-12-29,16:16:19,PST



#!/usr/bin/perl
#
# cur2csv.pl
#

use strict;
use vars qw($started);
use vars qw($cur_sym $cur_desc $usd_unit $units_usd);
use vars qw($year $month $mday $hour $minute $second $timezone);
use vars qw($conv_date $date $time $tz);


use Date::Manip;
use String::Strip;

use DBI;
use DBD::Pg;

open (OUTFILE, , currency.csv) || die Can not open currency.csv
for writing;

printf STDERR Reading currency file...;
open (INFILE, currency) || die Can not open /var/spool/mail/currency
for reading;

while (INFILE) {

# Extract date and time of Currency Rate Quotation

($year, $month, $mday, $hour, $minute, $second, $timezone) =
/^Rates as of (\d+).(\d+).(\d+) (\d+):(\d+):(\d+) (\w+) (.*)$/; 

# Convert date from UTC (GMT) to PST8PDT and adjust date and time
accordingly.

$tz = Date_TimeZone;   
$conv_date = $year-$month-$mday $hour:$minute:$second;
$conv_date = ParseDate($conv_date);
$conv_date = Date_ConvTZ($conv_date, $timezone, $tz);  
$date  = UnixDate($conv_date,%Y-%m-%d);
$time  = UnixDate($conv_date,%H:%M:%S);
$tz= UnixDate($conv_date,%Z);

$year and last;# If we've matched the data line, then bail out.

eof and print STDERR Didn't find the date line;

}

# Extract the ISO 4217 Code for Currencies and Funds (1995)
# Extract the Currency Description, and trim the trailing spaces
# Extract US Dollars to Units rate, and trim the leading/trailing
spaces
# Extract Units to US Dollars rate, and trim the leading/trailing
spaces

while (INFILE) {

($cur_sym, $cur_desc, $usd_unit, $units_usd) =
/^([A-Z]{3})\s+([A-Za-z()\s]{28})\s+(\d+\.\d+)\s+(\d+\.\d+)/;

# Strip the trailing spaces from $cur_desc
StripTSpace($cur_desc);

$cur_sym and $started++;

printf OUTFILE %s\,%s\,%s\,%s\,%s\,%s\,%s\n,
$date, $time, $tz, $cur_sym, $cur_desc, $usd_unit,
$units_usd;

not $cur_sym and ($started and last) or next;

$started or print STDERR Didn't find a currency line;

}   


close(INFILE);
close(OUTFILE);
print STDERR \n;

1;


--Confidentiality--.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.





Re: Regex problem

2001-05-29 Thread Jeff Pinyan

On May 28, Bornaz, Daniel said:

$stt=The food is under the bar in the barn in the river.;
$stt=~/bar(.*?)river/;
print $;

The output is:
bar in the barn in the river

Instead of the expected: 
barn in the river

For the meantime, you might like to look at chapter 6 of Learning Perl's
Regular Expressions[1], which provides an introduction to backtracking
and greediness.

The section, Leftmost-Longest, is the problem you've shown here.  While
the technique required to find the shortest possible match of all matches
is not yet explained in the book (it will be in chapter 8, which I'll be
working on today or tomorrow), I can tell you about it here.

In order to find the smallest number in a list, you have to go through all
the numbers in the list.  The same is true for a finding the shortest
match in a string.

  $_ = the food is at their bar by the barn in a barrel;
  my $match;

  # goal: find shortest string between 'e' and 'bar'
  while (/(?=(e.*?bar))/g) {
my $len = length $1;
$match = $1 if not defined $match or length($match)  $len;
  }

The way the approach works is it uses a look-ahead assertion, (?=...).

Look-ahead is JUST LIKE matching, without actually advancing in the
string.  It's like having a pair of binoculars with you on a hike.

We can make this approach even more robust, by demanding the regex match
less characters on each successive match:

  my $limit = '*';

  while (/(?=(e.$limit?bar))/g) {
my $len = length $1;
if (not defined $match or length($match)  $len) {
  $match = $1;
  $limit = {0,$len};
}
  }

This approach changes the $limit when a new shortest match is found.

Look forward (no pun intended) to seeing this in chapter 8.

[1] http://www.pobox.com/~japhy/docs/LPRE.html

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** I need a publisher for my book Learning Perl's Regular Expressions **





Re: Regex problem

2001-05-28 Thread Me

 Can anyone explain [Eager / Greedy], please?

Perl's regex engine is both Eager (Leftmost start)
and Greedy (Rightmost end).

The Greedy aspect is subservient to the Eager one.

The ? stops it being Greedy but not Eager.

To get the rightmost match, you could try adding
a .* at the start of the regex to greedily match from
the beginning.

See the Cookbook for more on this.




Re: Regex problem

2001-05-28 Thread Paul Dean

At 05:29 PM 28/05/2001 +0100, Bornaz, Daniel wrote:
Dear all,

I am trying the following code using ActivePerl 5.6.1.626, in my quest to
find the minimal string between bar and river:

$stt=The food is under the bar in the barn in the river.;
$stt=~/bar(.*?)river/;
print $;

The output is:
bar in the barn in the river

Instead of the expected:
barn in the river

 From what I read this would be correct, you are asking for everything but 
don't be greedy in between bar and river...
bar is an explicit match, if you want to match barn then I suggest this...

$stt=The food is under the bar in the barn in the river.;
$stt=~/barn(.*?)river/; # looks for barn not bar.
print $;


/* Experience is that marvelous thing that enables you to recognize a 
mistake when you make it again.
Franklin P. Jones */