find a value

2006-02-08 Thread Adriano Allora

Hi all,

is there a way to find a value in an array without a foreach loop?

thank you all a lot,

alladr

|^|_|^|_|^|  |^|_|^|_|^|
 || ||
 || ||
 ||*\_/*\_/*\_/*\_/*\_/* ||
 |   |
 |   |
 |   |
 | http://www.e-allora.net|
 |   |
 |   |
**


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




Re: find a value

2006-02-08 Thread Jeff Pang
If you just want to get a function to do that,I think the 'grep' should be 
fine.But it is essentially a foreach loop.
But you can get things more convenient by translating the array to hash and use 
the 'exist' function.

-Original Message-
>From: Adriano Allora <[EMAIL PROTECTED]>
>Sent: Feb 8, 2006 3:52 AM
>To: beginners@perl.org
>Subject: find a value
>
>Hi all,
>
>is there a way to find a value in an array without a foreach loop?
>
>thank you all a lot,
>
>alladr
>
>|^|_|^|_|^|  |^|_|^|_|^|   
>  || ||
>  || ||
>  ||*\_/*\_/*\_/*\_/*\_/* ||
>  |   |
>  |   |
>  |   |
>  |   http://www.e-allora.net|
>  |   |
>  |   |
>**
>
>
>-- 
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
> 
>
>


--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com

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




Re: find a value

2006-02-08 Thread Jimmy


Adriano Allora wrote:

Hi all,

is there a way to find a value in an array without a foreach loop?

thank you all a lot,

alladr

|^|_|^|_|^| |^|_|^|_|^|
| | | |
| | | |
| |*\_/*\_/*\_/*\_/*\_/* | |
| |
| |
| |
| http://www.e-allora.net |
| |
| |
**





Hi Adriano,

What do you looking for the "value" ?
The index location in the array or if a certain value existed in an array ?

by the way, perhaps you may refer to :
perldoc -f map
perldoc -f grep

hth
Jim


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




Math::BigInt maximum value

2006-02-08 Thread Rob Benton
What are the limitatins of Math::BigInt?  I ask because I have a c++ 
program that outputs an unsigned 64 bit integer that my perl script 
picks up.  Am I safe to use BigInt for this on all platforms?


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




Inserting data inside {}; --> aka "script to update named.conf handling zone"

2006-02-08 Thread bsd

Hello,


I am trying to use a modified version of the script produced by  
cricket Liu (DNS & BIND Cookbook) :



# more addzone.pl
#!/usr/bin/perl -w

$namedconf = "/etc/named.conf";

die "Usage: $0  \n" unless (@ARGV ==  
2);

$zone = $ARGV[0];
$datafile = $ARGV[1];

die "$namedconf must exist" unless (-r $namedconf);

open(NAMEDCONF, ">>$namedconf") || die "Couldn't open $namedconf";

open(TEMPFILE, "$datafile") || die "Couldn't open $datafile";

open(DATAFILE, ">hosts.$zone") || die "Couldn't open hosts.$zone";
@temp = ;
print DATAFILE @temp;
close(DATAFILE);
close(TEMPFILE);

print NAMEDCONF "zone \"", $zone, "\" {\n";
print NAMEDCONF "\ttype master;\n";
print NAMEDCONF "\tfile \"", "hosts.$zone", "\";\n";
print NAMEDCONF "};\n";

close(NAMEDCONF);

system("rndc reconfig") && die "Couldn't reconfig name server";




A version that will allow me to place the output of the printed  
statement (NAMEDCONF) inside the statement :



view external {

zone "141.15.165.in-addr.arpa" {
type master;
file "hosts.141.15.165.in-addr.arpa";
};

zone "bout.com" {
type slave;
masters  { 19.3.12.2 ; };
file "hosts.bout.com";
};

...


};



For the moment when I execute the script, my NAMEDCONF statments ends  
outside of the last "};" and I need It inside (because of zone  
handling matter.


I am a real beginner so any clue will be welcome.


Thanks a lot --




«?»¥«?»§«?»¥«?»§«?»¥«?»§«?»¥«?»§«?»¥«?»§«?»¥«?»§

Gregober ---> PGP ID --> 0x1BA3C2FD
bsd @at@ todoo.biz

«?»¥«?»§«?»¥«?»§«?»¥«?»§«?»¥«?»§«?»¥«?»§«?»¥«?»§





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




Re: Inserting data inside {}; --> aka "script to update named.conf handling zone"

2006-02-08 Thread Jeff Pang
hello,
In this situation you usually need to analyse the syntax of 'named.conf'.It is 
maybe a hard work based on the complexity of your file.Here,you can match the 
begin of 'view external {' block and add the additional lines from that 
location.I would do the modification as following:


my $cfgFile = "/etc/named.conf";

open (HD,$cfgFile) or die "$!";
my @config = ;
close HD;

open (NAMEDCONF,">",$cfgFile) or die "$!";
for (@config)
{
print NAMEDCONF $_;
if (/view external \{/)
{
print NAMEDCONF "zone \"", $zone, "\" {\n";
print NAMEDCONF "\ttype master;\n";
print NAMEDCONF "\tfile \"", "hosts.$zone", "\";\n";
print NAMEDCONF "};\n";
}
}
close NAMEDCONF;


Hope that helps.



-Original Message-
>From: bsd <[EMAIL PROTECTED]>
>Sent: Feb 8, 2006 7:14 PM
>To: Liste Perl 
>Subject: Inserting data inside {};  --> aka "script to update named.conf 
>handling zone"
>
>Hello,
>
>
>I am trying to use a modified version of the script produced by  
>cricket Liu (DNS & BIND Cookbook) :
>
>> # more addzone.pl
>> #!/usr/bin/perl -w
>>
>> $namedconf = "/etc/named.conf";
>>
>> die "Usage: $0  \n" unless (@ARGV ==  
>> 2);
>> $zone = $ARGV[0];
>> $datafile = $ARGV[1];
>>
>> die "$namedconf must exist" unless (-r $namedconf);
>>
>> open(NAMEDCONF, ">>$namedconf") || die "Couldn't open $namedconf";
>>
>> open(TEMPFILE, "$datafile") || die "Couldn't open $datafile";
>>
>> open(DATAFILE, ">hosts.$zone") || die "Couldn't open hosts.$zone";
>> @temp = ;
>> print DATAFILE @temp;
>> close(DATAFILE);
>> close(TEMPFILE);
>>
>> print NAMEDCONF "zone \"", $zone, "\" {\n";
>> print NAMEDCONF "\ttype master;\n";
>> print NAMEDCONF "\tfile \"", "hosts.$zone", "\";\n";
>> print NAMEDCONF "};\n";
>>
>> close(NAMEDCONF);
>>
>> system("rndc reconfig") && die "Couldn't reconfig name server";
>>
>
>
>A version that will allow me to place the output of the printed  
>statement (NAMEDCONF) inside the statement :
>
>> view external {
>>
>> zone "141.15.165.in-addr.arpa" {
>> type master;
>> file "hosts.141.15.165.in-addr.arpa";
>> };
>>
>> zone "bout.com" {
>> type slave;
>> masters  { 19.3.12.2 ; };
>> file "hosts.bout.com";
>> };
>>
>> ...
>>
>>
>> };
>
>
>For the moment when I execute the script, my NAMEDCONF statments ends  
>outside of the last "};" and I need It inside (because of zone  
>handling matter.
>
>I am a real beginner so any clue will be welcome.
>
>
>Thanks a lot --
>
>
>
>
>?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ
>
>Gregober ---> PGP ID --> 0x1BA3C2FD
>bsd @at@ todoo.biz
>
>?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ?ȴ?Ȥ
>
>
>
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
> 
>
>


--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com

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




array iteration problem

2006-02-08 Thread Graeme McLaren

Hi all, I have the following code:


# code
@cpv_codes=('a','a','a','a','b','b','b','c','c','d');

my %hash;
foreach (@letters) {
   $hash{$_}++;
   print "$_\t $hash{$_} \n";
}




and it prints:

a1
a2
a3
a4
b1
b2
b3
c1
c2
d1



What I really need is:

a = 4
b = 3
c = 2
d = 1


How would I do this?  Any ideas?


Cheers,

Graeme :)




Public Sub House()

On Error Resume drink

If Pint.empty = True Then
Pint.refill
  Else
Pint.drink
End if

stomach.add Pint

MsgBox " I've had  " & stomach.count & " Pints"
MsgBox "VERY DRUNK"

End Sub



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




Re: array iteration problem

2006-02-08 Thread Jeff Pang

>foreach (@letters) {
>$hash{$_}++;
>print "$_\t $hash{$_} \n";
>}

I think,the code should be written as below:

foreach (@letters) {
$hash{$_}++;
}

foreach (sort keys %hash){
print "$_ =  $hash{$_} \n";
}



--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com

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




Re: array iteration problem

2006-02-08 Thread John Doe
Graeme McLaren am Mittwoch, 8. Februar 2006 14.53:
> Hi all, I have the following code:

Hi Graeme

> # code

use strict; # forces declaring variables
use warnings;

> @cpv_codes=('a','a','a','a','b','b','b','c','c','d');

my @letters=(qw{ a a a a b b b c c d });

# qw (quote words) makes it easier to write and to look at :-)

> my %hash;
> foreach (@letters) {
> $hash{$_}++;
> print "$_\t $hash{$_} \n";
> }
> 
>
> and it prints:
>
> a1
> a2
> a3
> a4
[...]
> d1

The reason for that is that you print $hash{$_} *while* building it. 
What you see is how many times the just found char (in $_) has been seen in 
the array from its beginning to the current position.

> What I really need is:
>
> a = 4
> b = 3
> c = 2
> d = 1

Apart from Jeff's solution, there is also a shorter way:

$hash{$_}++ for @letters;
print map "$_\t$hash{$_}\n", sort keys %hash;

hth,
joe

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




Re: array iteration problem

2006-02-08 Thread JupiterHost.Net

Hello,


and it prints:

a1
a2
a3
a4
b1
b2
b3
c1
c2
d1



What I really need is:

a = 4
b = 3
c = 2
d = 1


>

How would I do this?  Any ideas?


You're printing each time its incremented, just print the keys and their 
value out *after* the for loop, also see:


perldoc -f map

# perl -mstrict -wle 'use Data::Dumper;my %letter_count;map { 
$letter_count{$_}++ } qw(a a a a b b b c c d);print Dumper \%letter_count;'

$VAR1 = {
  'c' => 2,
  'a' => 4,
  'b' => 3,
  'd' => 1
};

#

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




Re: array iteration problem

2006-02-08 Thread JupiterHost.Net

use strict; # forces declaring variables
use warnings;


yep yep :)


@cpv_codes=('a','a','a','a','b','b','b','c','c','d');



my @letters=(qw{ a a a a b b b c c d });


No neeed for the (), which also make sit easier to write and to look at :)


# qw (quote words) makes it easier to write and to look at :-)



my %hash;
foreach (@letters) {
   $hash{$_}++;
   print "$_\t $hash{$_} \n";
}


and it prints:

a1
a2
a3
a4


[...]


d1



The reason for that is that you print $hash{$_} *while* building it. 
What you see is how many times the just found char (in $_) has been seen in 
the array from its beginning to the current position.




What I really need is:

a = 4
b = 3
c = 2
d = 1



Apart from Jeff's solution, there is also a shorter way:

$hash{$_}++ for @letters;


Good point, better than the map{} I just sent


print map "$_\t$hash{$_}\n", sort keys %hash;


Not sure why you're using map here?

print "$_\t$hash{$_}\n" for sort keys %hash;

Also since strict and warnings have been recommended I might also poitin 
outthat %hash is a *very* bad name for a hash, its very ambiguouse and 
hard to maintain, The entire thing is clearly written as:


#!/usr/bin/perl

use strict;
use warnings;

my %letter_count;
my @letters = qw(a a a a b b b c c d T M B G R O C K S);

$letter_count{$_}++ for @letters;

print "$_\t$letter_count{$_}\n" for sort keys %letter_count;


Of course if you really wanted to get strict your 1st for() loop would 
check that the character is indeed a letter, that its one character, and 
only then add it to the hash with the ++ :) (and also does case matter? 
it'd need to handle that too)


So for instance to treat upper and lowercase the same (IE 't' is 
considered the same as 'T')


for my $letter(@letters) {
$letter_count{ lc($letter) }++ if lc($letter) =~ m{^[a-z]$};
}


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




question about installing snmp-info module

2006-02-08 Thread Gebe, WJ
Hi 

 

I  tray to install the snmp-info module on my win32 perl envo.

 

But with ppm the module came not in the search result

 

And installing the module with the tar file downloaded from cpan  is not
working because of win 32 as no make command.

And nmake do not please the files in the correct destination files 

 

Is there someone out there how wants to help 

 

I have a 5.6 and a 5.8 installation of perl..

 

 

 

thanks

 

W.J. Gebe

Netwerk beheerder 

 

Vrije Universiteit Amsterdam

Dienst IT/NIS, kamer 0E-20

De Boelelaan 1101

1081 H.V. Amsterdam

 

Tel.  : 020-5985386

Fax. : 020-5985391

Email   : [EMAIL PROTECTED]

Inet  : http://www.vu.nl

 



Re: array iteration problem

2006-02-08 Thread Bjørge Solli
On Wednesday 08 February 2006 15:51, JupiterHost.Net wrote:
> So for instance to treat upper and lowercase the same (IE 't' is
> considered the same as 'T')
>
> for my $letter(@letters) {
>  $letter_count{ lc($letter) }++ if lc($letter) =~ m{^[a-z]$};
> }

or just (untested):
$letter_count{$_}++ for map lc, @letters;

-- 
Bjørge Solli - Office:+47 55205847 cellph.:+47 91614343
Nansen Environmental and Remote Sensing Center - Bergen, Norway
http://www.nersc.no Reception: +47 55205800
Dept.: Mohn-Sverdrup Center for Global Ocean Studies 
   and Operational Oceanography

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




Re: array iteration problem

2006-02-08 Thread John Doe
JupiterHost.Net am Mittwoch, 8. Februar 2006 15.51:
> > use strict; # forces declaring variables
> > use warnings;
>
> yep yep :)
>
> >>@cpv_codes=('a','a','a','a','b','b','b','c','c','d');
> >
> > my @letters=(qw{ a a a a b b b c c d });
>
> No neeed for the (), which also make sit easier to write and to look at :)

Nice, I never considered omitting the (), thanks :-)

[...]
> > $hash{$_}++ for @letters;
>
> Good point, better than the map{} I just sent
>
> > print map "$_\t$hash{$_}\n", sort keys %hash;
>
> Not sure why you're using map here?

because print is only called once and not for every iteration. 
Look at the following benchmark:

use strict;
use warnings;
use Benchmark;
my @words='word' x 10;
timethese(1000, {
  'for' => 'print $_ for @words;',
  'map' => 'print map {$_} @words;'
});


Benchmark: timing 1000 iterations of for, map...
   for: 14 wallclock secs ( 9.18 usr +  0.00 sys =  9.18 CPU) @ 
1089324.62/s (n=1000)
   map:  5 wallclock secs ( 3.55 usr +  0.02 sys =  3.57 CPU) @ 
2801120.45/s (n=1000)


> print "$_\t$hash{$_}\n" for sort keys %hash;
>
> Also since strict and warnings have been recommended I might also poitin
> outthat %hash is a *very* bad name for a hash, its very ambiguouse and
> hard to maintain, 

Why is %hash a very bad name? 
Is @array also a bad name?
And what's the relationship with using strict and/or warnings?

> The entire thing is clearly written as: 
[...]

greetings
joe

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




Need to login to a site and get data

2006-02-08 Thread Vikram Goyal
Hello,

Being new to perl, I need your help and guidance in solving one problem.

I want to login to a site through scripts and retreive data. I was doing
it till now through expect and lynx text browser's ability to record a
session and run the commands.

I think it's possible through perl and it's numerous modules. Can anyone
point me as to how it may be done.

Thanks!
-- 
vikram...
 
 
^^'^^||root||^^^'''^^
// \\   ))
   //(( \\// \\
  // /\\ ||   \\
 || / )) ((\\
-- 
economist, n:
Someone who's good with figures, but doesn't have enough
personality to become an accountant.
-- 
 #
~|~
 =
Registered Linux User #285795

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




Re: Need to login to a site and get data

2006-02-08 Thread Luke Bakken
> I want to login to a site through scripts and retreive data. I was doing
> it till now through expect and lynx text browser's ability to record a
> session and run the commands.
>
> I think it's possible through perl and it's numerous modules. Can anyone
> point me as to how it may be done.

LWP::UserAgent is what you're looking for.

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




Re: Need to login to a site and get data

2006-02-08 Thread Vikram Goyal
On Wed, Feb 08, 2006 at 08:54:26AM -0800, Luke Bakken wrote:
> > I want to login to a site through scripts and retreive data. I was doing
> > it till now through expect and lynx text browser's ability to record a
> > session and run the commands.
> >
> > I think it's possible through perl and it's numerous modules. Can anyone
> > point me as to how it may be done.
> 
> LWP::UserAgent is what you're looking for.
> 

Thanks for the input. One thing I forgot to mention was that the site
uses javascript which caused me to turn to perl as lynx does not support
it.

Regards!
-- 
vikram...
 
 
^^'^^||root||^^^'''^^
// \\   ))
   //(( \\// \\
  // /\\ ||   \\
 || / )) ((\\
-- 
Diplomacy is to do and say, the nastiest thing in the nicest way.
-- Balfour
-- 
 *
~|~
 =
Registered Linux User #285795

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




Re: Need to login to a site and get data

2006-02-08 Thread Luke Bakken
> Thanks for the input. One thing I forgot to mention was that the site
> uses javascript which caused me to turn to perl as lynx does not support
> it.

You will have to determine manually how the website uses javascript
and code LWP::UserAgent appropriately to send the correct information
in the POST/GET requests as well as cookies. I did this to get my
balances from my bank's online services - it's a pain to get working
right but works well once you do.

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




Re: Need to login to a site and get data

2006-02-08 Thread Vikram Goyal
On Wed, Feb 08, 2006 at 09:11:06AM -0800, Luke Bakken wrote:
> > Thanks for the input. One thing I forgot to mention was that the site
> > uses javascript which caused me to turn to perl as lynx does not support
> > it.
> 
> You will have to determine manually how the website uses javascript
> and code LWP::UserAgent appropriately to send the correct information
> in the POST/GET requests as well as cookies. I did this to get my
> balances from my bank's online services - it's a pain to get working
> right but works well once you do.
> 

Thanks, I'll look in the code and would ask for your help if I get stuck
up somewhere.
-- 
vikram...
 
 
^^'^^||root||^^^'''^^
// \\   ))
   //(( \\// \\
  // /\\ ||   \\
 || / )) ((\\
-- 
We only acknowledge small faults in order to make it appear that we are
free from great ones.
-- La Rouchefoucauld
-- 
 _
~|~
 =
Registered Linux User #285795

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




Re: Math::BigInt maximum value

2006-02-08 Thread Tom Phoenix
On 2/8/06, Rob Benton <[EMAIL PROTECTED]> wrote:

> What are the limitatins of Math::BigInt?  I ask because I have a c++
> program that outputs an unsigned 64 bit integer that my perl script
> picks up.  Am I safe to use BigInt for this on all platforms?

Have you seen the wording "Arbitrary size integer math package" at the
top of the docs for the module? BigInts can be as big as memory will
allow. Given sufficient memory, you should be able to work with
numbers with hundreds or thousands or even millions of bits using
Math::BigInt. If, after all that, you've still got a few dozen free
bytes, you could include a tiny 64-bit integer too. :-)  Cheers!

--Tom Phoenix
Stonehenge Perl Training

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




Expect using expect.pm in perl

2006-02-08 Thread Leif Ericksen
I am working on a little project where I want to use expect in Perl, and
I am having some luck already but wanted to know what is the recommended
books to learn more about using expect in Perl.  Will the Expect books
by O'Reilly be of value for this?

So far I am using the sample code from the module distribution as well
as some documents from cpan.org, as well as just putting together some
code on a trial and error basis.  Call me crazy there may be a better
way to do what I am doing, but I want to use it as an excuse to learn
expect in perl.  ;)


-- 
Leif Ericksen <[EMAIL PROTECTED]>


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




Re: Expect using expect.pm in perl

2006-02-08 Thread Owen Cook

On Wed, 8 Feb 2006, Leif Ericksen wrote:

> I am working on a little project where I want to use expect in Perl, and
> I am having some luck already but wanted to know what is the recommended
> books to learn more about using expect in Perl.  Will the Expect books
> by O'Reilly be of value for this?
> 
> So far I am using the sample code from the module distribution as well
> as some documents from cpan.org, as well as just putting together some
> code on a trial and error basis.  Call me crazy there may be a better
> way to do what I am doing, but I want to use it as an excuse to learn
> expect in perl.  ;)


It might be a good idea to read 'man expect' before 'perldoc Expect'



Owen


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




Re: regular expressions over multiple lines

2006-02-08 Thread Gretar M. Hreggvidsson

Hi

The simplest approuch would be to something like this:

# @files contains the files to be processed.
for my $file (@files){
  my $content;
  local $/ = '';  # Sets the INPUT_RECORD_SEPERATOR as empty string

  open(IN, $file)
or warn "Couldn't open $file for reading: $!";
  $content = ;
  close(IN);

  # Take everything that's between EXP1 and EXP2 if they exist
  if ($content =~ /EXP1(.+)EXP2/s){
print $1;  # Contains what's between the parenthesis
  }
}

Best regards,
Grétar

Rimma Nayshulis wrote:

Hi,
  I've never used perl before, but was told that it's pretty powerful for text 
processing.
  Here's a problem I'm trying to solve:
  I have an expression, exp1 that I need to grep for recursively over a  
directory structure.  If I find a match, I need to look at the  matching file 
and find another expression, exp2.  Both exp1 and  exp2 belong to the same 
pattern that always looks like this
  {
  exp2 "some text"
  some lines of text
  some lines of tex
  .
  exp1
  more lines of text
  more lines of text
  
  }
  
  The goal of this exercise is to see what "some text" says in the files that contain exp1.  
  I can always read all of the files recursively line by line, save each  line into an array until I find exp1 and then go backwards through the  array until I find exp2 and see what "some text" on that line is, but I  was wondering if I can somehow use regular expressions over multiple  lines to do this.

  I hope this is a clear explanation of my problem.
  Any insights or pointers to resourcesare greatly appreciated!
  Thanks!
  
  
  
  
		

-
Relax. Yahoo! Mail virus scanning helps detect nasty viruses!


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




Regex puzzler!

2006-02-08 Thread Mike Blezien

Hello,

I'm trying to extract an image name from the follow html tag

$imageURL = ""

now I need to extract the 'thebest_Small.png' filename from the img tag, but 
havent't been able to figure out how to do this correctly.


i tried:
$imageURL =~ !!;
$pic  = $1;

but that produces errors. what I'm doing wrong here ??

TIA,
--
Mike(mickalo)Blezien


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




Re: Regex puzzler!

2006-02-08 Thread Peter Cornelius
The first thing that jumps out at me is that the '.*' pattern is  
going to be a greedy match.  This means it will match everything,  
swallowing the '" BORDER=0> part of the string too.  You can make the  
* non-greedy by putting a '?' after it.


$imageURL =~ !!;

but you might be better off with a character class

$imageURL =~ !!;

This might work for you tho I haven't tried it.  I seem to remember  
an HTML::Parser library on CPAN that might make you life easier if  
your parsing html docs.


PC

On Feb 8, 2006, at 6:34 PM, Mike Blezien wrote:


Hello,

I'm trying to extract an image name from the follow html tag

$imageURL = "BORDER=0>"


now I need to extract the 'thebest_Small.png' filename from the img  
tag, but havent't been able to figure out how to do this correctly.


i tried:
$imageURL =~ !!;
$pic  = $1;

but that produces errors. what I'm doing wrong here ??

TIA,
--
Mike(mickalo)Blezien


--
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 puzzler!

2006-02-08 Thread Tom Phoenix
On 2/8/06, Mike Blezien <[EMAIL PROTECTED]> wrote:

> I'm trying to extract an image name from the follow html tag

> i tried:
> $imageURL =~ !!;
> $pic  = $1;
>
> but that produces errors. what I'm doing wrong here ??

Your small error is forgetting that the question mark is a
metacharacter. See the perlre documentation.

Your medium error is misusing the syntax of the m// pattern match
operator. See perlop.

Your large error is trying to use a regular expression to manipulate
HTML. Use a robust module from CPAN.

http://search.cpan.org/

You could get away with a pattern instead of a module if you have a
very simple case. But using a module means a simpler pattern, and less
chance of something going wrong as a result.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

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




Re: Regex puzzler!

2006-02-08 Thread Mike Blezien
this is what I ended up doing and it seems to work, unless you see a potiental 
problem with it:


$imageURL =~ //;
$audioimage = $1;

this give the image filename i needed.

Mike

Tom Phoenix wrote:

On 2/8/06, Mike Blezien <[EMAIL PROTECTED]> wrote:



I'm trying to extract an image name from the follow html tag




i tried:
$imageURL =~ !!;
$pic  = $1;

but that produces errors. what I'm doing wrong here ??



Your small error is forgetting that the question mark is a
metacharacter. See the perlre documentation.

Your medium error is misusing the syntax of the m// pattern match
operator. See perlop.

Your large error is trying to use a regular expression to manipulate
HTML. Use a robust module from CPAN.

http://search.cpan.org/

You could get away with a pattern instead of a module if you have a
very simple case. But using a module means a simpler pattern, and less
chance of something going wrong as a result.

Hope this helps!



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




Re: Regex puzzler!

2006-02-08 Thread Tom Phoenix
On 2/8/06, Mike Blezien <[EMAIL PROTECTED]> wrote:

> this is what I ended up doing and it seems to work, unless you see a potiental
> problem with it:
>
> $imageURL =~ //;
> $audioimage = $1;
>
> this give the image filename i needed.

Cool! I'm glad you got it to work. And, so long as you don't mind that
the pattern is fragile, I don't have a problem with it. By fragile, I
mean that any small change in the syntax of the HTML is likely to make
it fail to match:



I don't know the details of your situation, so I can't know whether
this matters. If you know that your input data is restricted to what
your pattern matches, that the syntax will never change, that nobody
will ever add height, width, alt text, or other attributes to your
tags, then go for it. Or you can use a module.

In normal usage, it's best to check the return value of your pattern
match: If it's false, the match failed, $1 may have a value left over
from a previous pattern match, and you may want to die() to alert the
user that the pattern needs to be tweaked.

Cheers!

--Tom Phoenix
Stonehenge Perl Training

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




Re: Regex puzzler!

2006-02-08 Thread John W. Krahn
Mike Blezien wrote:
> Hello,

Hello,

> I'm trying to extract an image name from the follow html tag
> 
> $imageURL = ""
> 
> now I need to extract the 'thebest_Small.png' filename from the img tag,
> but havent't been able to figure out how to do this correctly.
> 
> i tried:
> $imageURL =~ !!;
> $pic  = $1;
> 
> but that produces errors. what I'm doing wrong here ??

You are trying to use the match operator incorrectly.  Only the delimiters //
and ?? can be used without the 'm' in front.

$imageURL =~ m!!;


John
-- 
use Perl;
program
fulfillment

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




WIN32::OLE problem while reading the date format

2006-02-08 Thread swayam panda

Hi ALL,

I am reading some values from the Excel file by using Win32::OLE,I 
am able to read  all fields bur not able able read if the date is in 
dd/mm/yy( i.e / slash) .If i am using backward slash then the date is 
working .Can any body tell me how to read the a date from the EXCEL file



Example  EXCEL file

 TESTERNAME Swayam
 DATE 9/2/2006
 DEVICETYPE SOLARIS
 HARDWAREVERSION vx34.56



if i am reading the file  then i am able to get the values of 
TESTER_NAME,DEVICE_TYPE,HARDWARE_VERSION but it's not able to take the value 
of DATE. but if i am using backward slash (\) then it's working .


Part  of my code



open (FILE,">>reportfile") or die "can't open $!";

for ($i = 1; $i <=12 ; $i++)
{
   # Skip over empty cells
   if ( (!defined($sheet->Range('A'.$i)->{'Value'}))  )
   {
  next;
   }

   elsif ($sheet->Range('A'.$i)->{'Value'} eq  "TESTERNAME")
   {

 print  FILE "#" . $sheet->Range('A'.$i)->{'Value'} . " :\t\t" 
.$sheet->Range('B'.$i)->{'Value'}. "\n";

   }

   elsif ($sheet->Range('A'.$i)->{'Value'} eq  "DATE")
   {
 print FILE "#" . $sheet->Range('A'.$i)->{'Value'} ." :\t\t\t" 
."$sheet->Range('B'.$i)->{'Value'}"."\n";

   }

   elsif ($sheet->Range('A'.$i)->{'Value'} eq  "DEVICETYPE")
   {
 print FILE "#" . $sheet->Range('A'.$i)->{'Value'} . " :\t\t" 
.$sheet->Range('B'.$i)->{'Value'}. "\n";

   }

   elsif ($sheet->Range('A'.$i)->{'Value'} eq  "HARDWAREVERSION")
   {
 print FILE "#" . $sheet->Range('A'.$i)->{'Value'} . " :\t" 
.$sheet->Range('B'.$i)->{'Value'}. "\n";

   }
}

But the same code is working if in the excel file (which i am reading ) i am 
using date format as 06\02\2006 ( back ward slash)



Thanks 



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




Re: WIN32::OLE problem while reading the date format

2006-02-08 Thread Alfred Vahau
See Win32::OLE::Variant on ActiveState Perl Documentation on how to read 
the date correctly.


Alfred,

swayam panda wrote:


Hi ALL,

I am reading some values from the Excel file by using 
Win32::OLE,I am able to read  all fields bur not able able read if the 
date is in dd/mm/yy( i.e / slash) .If i am using backward slash then 
the date is working .Can any body tell me how to read the a date from 
the EXCEL file



Example  EXCEL file

 TESTERNAME Swayam
 DATE 9/2/2006
 DEVICETYPE SOLARIS
 HARDWAREVERSION vx34.56



if i am reading the file  then i am able to get the values of 
TESTER_NAME,DEVICE_TYPE,HARDWARE_VERSION but it's not able to take the 
value of DATE. but if i am using backward slash (\) then it's working .


Part  of my code



open (FILE,">>reportfile") or die "can't open $!";

for ($i = 1; $i <=12 ; $i++)
{
   # Skip over empty cells
   if ( (!defined($sheet->Range('A'.$i)->{'Value'}))  )
   {
  next;
   }

   elsif ($sheet->Range('A'.$i)->{'Value'} eq  "TESTERNAME")
   {

 print  FILE "#" . $sheet->Range('A'.$i)->{'Value'} . " :\t\t" 
.$sheet->Range('B'.$i)->{'Value'}. "\n";

   }

   elsif ($sheet->Range('A'.$i)->{'Value'} eq  "DATE")
   {
 print FILE "#" . $sheet->Range('A'.$i)->{'Value'} ." :\t\t\t" 
."$sheet->Range('B'.$i)->{'Value'}"."\n";

   }

   elsif ($sheet->Range('A'.$i)->{'Value'} eq  "DEVICETYPE")
   {
 print FILE "#" . $sheet->Range('A'.$i)->{'Value'} . " :\t\t" 
.$sheet->Range('B'.$i)->{'Value'}. "\n";

   }

   elsif ($sheet->Range('A'.$i)->{'Value'} eq  "HARDWAREVERSION")
   {
 print FILE "#" . $sheet->Range('A'.$i)->{'Value'} . " :\t" 
.$sheet->Range('B'.$i)->{'Value'}. "\n";

   }
}

But the same code is working if in the excel file (which i am reading 
) i am using date format as 06\02\2006 ( back ward slash)



Thanks



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