parsing post parameters

2008-01-09 Thread perlmunky
Hi list,

I am working on a catalyst project and would have been attempting to create
a user page (form) that allows someone to create an sql query to hammer a
local DB (all secure-ish - maybe).  I have used a javascript function to
return the post options and used the catalyst method
$c->request->parameters() to get at the form information.

The information is contained within a hash (ref to a hash) and the values
are either scalar or arrays.  What I would like to know is if there is a way
of testing the type of a variable - as with python:

>>> foo = ["a", "b", "c"]
>>> type(foo)


or if there is a way to convert the scalars into arrays - allowing me to
skip the check.  I have tried to use a JSON hash in the javascript but this
has not worked - I also *assume* that I would be presented with the same
problem - parsing that hash of mixed variables.

I am sorry if this is a stupid question.

Thanks


Re: print a selection of a file

2008-01-09 Thread Martin Barth
> #!/opt/perl/bin/perl  -w
> use  strict;
>
> #variable
>
> my @horcm_file;
>
>
> sub  readdata{
>   open(HORCM, "/etc/horcm10.conf") || die  ("File error");
>   @horcm_file = ;
>   chomp(@horcm_file);
>   close(HORCM);
>   return(@horcm_file);
> }
>
> my @pipo=readdata();
>
> foreach (@pipo){
>   /HORCM_INST/ or next;
>   print;
> }
>

I would not store the whole file into an array unless you really need this.


i would suggest this sollution:


my $outputflag = 0;
open(HORCM, "/etc/horcm10.conf") || die  ("File error");
while(){
if(/HORCM_INST/){
  $outputflag = 1; # start printing
}elsif($_ eq "\n") { #newline
  $outputflag = 0; # stop printing
}
print if $outputflag;

}
close(HORCM);

HTH, Martin


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




print a selection of a file

2008-01-09 Thread jonay . herrera
Hello,

I try  to  print (get)  a specific text selection from  a  text file,
but  I don't know  how to  do  it:
What I try  todo  is  to open a  file search  a string and  print
the  follow lines from that  string until he found  a white line. then
he need to stop.  so can i  get  the  lines (strings) that i need.

#!/opt/perl/bin/perl  -w
use  strict;

#variable

my @horcm_file;


sub  readdata{
  open(HORCM, "/etc/horcm10.conf") || die  ("File error");
  @horcm_file = ;
  chomp(@horcm_file);
  close(HORCM);
  return(@horcm_file);
}

my @pipo=readdata();

foreach (@pipo){
  /HORCM_INST/ or next;
  print;
}


thanks in advance,

Jonay


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




Re: parsing post parameters

2008-01-09 Thread Paul Lalli
On Jan 9, 4:57 am, [EMAIL PROTECTED] (Perlmunky) wrote:
> Hi list,
>
> I am working on a catalyst project and would have been attempting to create
> a user page (form) that allows someone to create an sql query to hammer a
> local DB (all secure-ish - maybe).  I have used a javascript function to
> return the post options and used the catalyst method
> $c->request->parameters() to get at the form information.
>
> The information is contained within a hash (ref to a hash) and the values
> are either scalar or arrays.  What I would like to know is if there is a way
> of testing the type of a variable - as with python:
>
> >>> foo = ["a", "b", "c"]
> >>> type(foo)
>
> 
>
> or if there is a way to convert the scalars into arrays - allowing me to
> skip the check.  I have tried to use a JSON hash in the javascript but this
> has not worked - I also *assume* that I would be presented with the same
> problem - parsing that hash of mixed variables.

I'm having difficulty parsing your question to figure out what you're
asking, but I think what you're looking for is the ref() function,
which returns a true value if given a reference (actually, it returns
a string representing what type of reference it's given: 'ARRAY',
'HASH', 'CODE', 'SCALAR', etc), and returns a false value if given a
non-reference.

ref([EMAIL PROTECTED]) ==> 'ARRAY'
ref(\$foo) ==> 'SCALAR'
ref(\%foo) ==> 'HASH'
ref("foo") ==> ''

perldoc -f ref
for more information

Paul Lalli


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




Re: print a selection of a file

2008-01-09 Thread Paul Lalli
On Jan 9, 4:36 am, [EMAIL PROTECTED] (Jonay Herrera) wrote:
> Hello,
>
> I try  to  print (get)  a specific text selection from  a  text file,
> but  I don't know  how to  do  it:
> What I try  todo  is  to open a  file search  a string and  print
> the  follow lines from that  string until he found  a white line. then
> he need to stop.  so can i  get  the  lines (strings) that i need.
>
> #!/opt/perl/bin/perl  -w
> use  strict;
>
> #variable
>
> my @horcm_file;
>
> sub  readdata{
>   open(HORCM, "/etc/horcm10.conf") || die  ("File error");
>   @horcm_file = ;
>   chomp(@horcm_file);
>   close(HORCM);
>   return(@horcm_file);
>
> }
>
> my @pipo=readdata();
>
> foreach (@pipo){
>   /HORCM_INST/ or next;
>   print;
>
> }

You're looking for the "flip flop" operator, which looks just like the
range operator: ..

while (my $line = <$file>) {
   if (/HORCM_INST/ .. /^\s*$/) {
   print $line;
   }
}

read more about it in:
perldoc perlop

Paul Lalli


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




Re: Error installing a module - what do I do?

2008-01-09 Thread yitzle
It all seemed to have worked. Except I get an error when I try to use it:
__ERROR__
Can't locate Devel/Sysdump.pm in @INC (@INC contains:
/usr/lib/perl5/5.8/cygwin /usr/lib/perl5/5.8
/usr/lib/perl5/site_perl/5.8/cygwin /usr/lib/perl5/site_perl/5.8
/usr/lib/perl5/site_perl/5.8 /usr/lib/perl5/vendor_perl/5.8/cygwin
/usr/lib/perl5/vendor_perl/5.8 /usr/lib/perl5/vendor_perl/5.8 .) at
./KF.pl line 4.
__END__

>From make install:
$ make install
Installing /usr/lib/perl5/site_perl/5.8/Devel/Symdump.pm
Installing /usr/lib/perl5/site_perl/5.8/Devel/Symdump/Export.pm
Writing /usr/lib/perl5/site_perl/5.8/cygwin/auto/Devel/Symdump/.packlist
Appending installation info to /usr/lib/perl5/5.8/cygwin/perllocal.pod

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




Re: Error installing a module - what do I do?

2008-01-09 Thread Peter Scott
On Wed, 09 Jan 2008 10:06:51 -0500, yitzle wrote:
> It all seemed to have worked. Except I get an error when I try to use it:
> __ERROR__
> Can't locate Devel/Sysdump.pm in @INC (@INC contains:
   ^

> $ make install
> Installing /usr/lib/perl5/site_perl/5.8/Devel/Symdump.pm
  ^

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


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




Re: Error installing a module - what do I do?

2008-01-09 Thread yitzle
>From before:

$ make install
Installing /usr/lib/perl5/site_perl/5.8/Devel/Symdump.pm

(@INC contains: ...
/usr/lib/perl5/site_perl/5.8

On 1/9/08, Peter Scott <[EMAIL PROTECTED]> wrote:
> On Wed, 09 Jan 2008 10:06:51 -0500, yitzle wrote:
> > It all seemed to have worked. Except I get an error when I try to use it:
> > __ERROR__
> > Can't locate Devel/Sysdump.pm in @INC (@INC contains:
>^
>
> > $ make install
> > Installing /usr/lib/perl5/site_perl/5.8/Devel/Symdump.pm
>   ^
>
> --
> Peter Scott
> http://www.perlmedic.com/
> http://www.perldebugged.com/
>

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




Re: Error installing a module - what do I do?

2008-01-09 Thread yitzle
On 1/9/08, Chas. Owens <[EMAIL PROTECTED]> wrote:
> If you switch to a monospace font you will see that the caret
> character is pointing to the third character in Sysdump and Symdump
> respectively, not to the directory.

Oops.
OK. I guess its working now ;)
Thanks, everyone, for the help!

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




perl template toolkit - modify variable

2008-01-09 Thread perlmunky
Hi list,

I am trying to generate a web page containing a form which is constructed
automagically with catalyst.
The variable which is passed to the template is an array (  [% column_names
%]  )

each element in the array looks like:
   foo.bar
   foo.baz
   oof.rab
   oof.zab
...

As I loop over the array I would like to split the 'foo.baz' into  'foo' and
'baz' and keep 'foo.baz'
My current code looks like this:



 
 
   
where

 
 [% FOR name IN column_names %]
[% name.0 %]
 [% END %]



[% FOR qual IN qual_options %]
[% qual %]
[% END %]


 



Basically, I would like to display the option value as baz, but have the
full name in the post.
How on earth can this be done in the template.

The way I have considered doing this is to duplicate arrays - however the
template toolkit seems to be without for (my $i = 0 ... )

Sorry if this is (yet another) stupid question.


Re: Error installing a module - what do I do?

2008-01-09 Thread Chas. Owens
On Jan 9, 2008 10:50 AM, yitzle <[EMAIL PROTECTED]> wrote:
snip
> > > Can't locate Devel/Sysdump.pm in @INC (@INC contains:
> >^
> >
> > > $ make install
> > > Installing /usr/lib/perl5/site_perl/5.8/Devel/Symdump.pm
> >   ^
snip
> From before:
>
> $ make install
> Installing /usr/lib/perl5/site_perl/5.8/Devel/Symdump.pm
>
> (@INC contains: ...
> /usr/lib/perl5/site_perl/5.8
>
snip

If you switch to a monospace font you will see that the caret
character is pointing to the third character in Sysdump and Symdump
respectively, not to the directory.

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




Re: perl template toolkit - modify variable

2008-01-09 Thread perlmunky
Sorry, I am a fool.  I found the methods in the VMethods section of the tt
website.  Sorry.
I have used:
 name.0.remove('.*\.')
to sort the problem

On Jan 9, 2008 4:13 PM, perlmunky <[EMAIL PROTECTED]> wrote:

> Hi list,
>
> I am trying to generate a web page containing a form which is constructed
> automagically with catalyst.
> The variable which is passed to the template is an array (  [%
> column_names %]  )
>
> each element in the array looks like:
>foo.bar
>foo.baz
>oof.rab
>oof.zab
> ...
>
> As I loop over the array I would like to split the 'foo.baz' into  'foo'
> and 'baz' and keep 'foo.baz'
> My current code looks like this:
>
> 
> 
>  
>  
>
> where
> 
>  
>  [% FOR name IN column_names %]
> [% name.0 %]
>  [% END %]
> 
>
> 
> [% FOR qual IN qual_options %]
> [% qual %]
> [% END %]
> 
> 
>  
> 
> 
>
> Basically, I would like to display the option value as baz, but have the
> full name in the post.
> How on earth can this be done in the template.
>
> The way I have considered doing this is to duplicate arrays - however the
> template toolkit seems to be without for (my $i = 0 ... )
>
> Sorry if this is (yet another) stupid question.
>
>


Re: find2perl

2008-01-09 Thread oryann9


oryann9> No, but good point. My intent was to determine when -prune was
 set on
oryann9> the CLI what the De-parsed code told me, 1==true, 0==false
 because
oryann9> when I run this code below prune = 0 is not working, its
 descending
oryann9> down "/".

You're misusing it.  Set it within the wanted() routine when you're
 looking at
a directory that you don't want to descend.  It'll be cleared to 0
 before
calling wanted(), so setting it before calling find() is completely
 useless.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.



-

__OUTPUT__

main::(find_hog:47):if ( $fs eq "/" ) { # only if the root directory
  DB<1> print $fs
/
  DB<2> n
main::(find_hog:48):find_me ( $fs, 0 );
  DB<2> n

print caller find_me
main::(find_hog:61):my ( @sorted_large_files, @large_files ) ;
  DB<2>
main::(find_hog:80):if (@sorted_large_files) {
  DB<2> print caller find_me
invalid top directory at /opt/perl/lib/5.8.2/File/Find.pm line 568, <> line 1.

  DB<3> print $fs
/
  DB<4> n
main::(find_hog:81):my %meta ;
  DB<4> n
main::(find_hog:82):for my $file (@sorted_large_files) {
DB<4> n
main::(find_hog:83):$meta{$file} = {
main::(find_hog:84): 'uid' => (stat($file))[4],
main::(find_hog:85): 'gid' => (stat($file))[5],
main::(find_hog:86): 'sz'  => (stat($file))[7],
main::(find_hog:87): 'mod' => (stat($file))[9],
  DB<4> print $file
/data/data01/recovery/archives/dubhdv04/2007-11-15,11:21
  DB<5>

/data/... should not be appearing if prune set to false, or 0.

__CODE__

Is this what you mean on line 9? I tried and it does not seem to work, meaning 
it still descending.

1 sub find_me {
2  use Data::Dumper;
3  my $fs = shift;
4  #local $File::Find::prune = shift; ##-- localize prune to just 
this block --##
5  #my @directory = ($fs) ;
6  use constant MAX_SIZE => (25*1024*1024) ;
7  use constant DIVISOR  => (1024) ;
8  my ( $wanted, $list ) = find_by_min_size ( MAX_SIZE ) ;
9  File::Find::find ( { wanted => $wanted, prune => 
$File::Find::prune = shift}, $fs ) ;
10@large_files = $list->() ;
11
12@sorted_large_files =
13 sort { -s $b <=> -s $a }
14@large_files ;
15
16   } ##-- End sub --##





  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

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




More installing modules issues - using a local directory

2008-01-09 Thread yitzle
I installed LWP manually into a local directory (~/perl)
When I try to install WWW::Mechanize, it finds the old version - not
the new local version - and fails.

> perl Makefile.PL
-snip-
> Warning: prerequisite LWP 5.802 not found. We have 5.79.

The make test fails miserably.
How do I modify the lib path for an install?

Thanks

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




Re: More installing modules issues - using a local directory

2008-01-09 Thread Tom Phoenix
On Jan 9, 2008 1:38 PM, yitzle <[EMAIL PROTECTED]> wrote:

> I installed LWP manually into a local directory (~/perl)
> When I try to install WWW::Mechanize, it finds the old version - not
> the new local version - and fails.

The new version needs to be the first one found by looking in the @INC
directories, but your @INC probably doesn't include the local
directory. You probably want to set the PERL5LIB environment variable.
When I need this sort of thing, I put something like this in my
~/.bash_profile, so that it takes effect automatically in each new
shell; your shell may require different syntax, and your path may need
to be different:

   export PERL5LIB=~/perl/

When perl starts running, it will normally add the directories in
PERL5LIB to the start of @INC before it starts compiling your program,
resembling what would happen if each program had a 'use lib' line
added near the top. Using the correct path should allow the
installation program to find the right module.

Good luck with it!

--Tom Phoenix
Stonehenge Perl Training

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




Re: find2perl

2008-01-09 Thread Tom Phoenix
On Jan 9, 2008 12:21 PM, oryann9 <[EMAIL PROTECTED]> quoted Randal Schwartz:

> > You're misusing it.  Set it within the wanted() routine when you're

> Is this what you mean on line 9? I tried and it does not seem to work,
> meaning it still descending.
>
> 1 sub find_me {
> 2  use Data::Dumper;
> 3  my $fs = shift;
> 4  #local $File::Find::prune = shift; ##-- localize prune to just 
> this block --##
> 5  #my @directory = ($fs) ;
> 6  use constant MAX_SIZE => (25*1024*1024) ;
> 7  use constant DIVISOR  => (1024) ;
> 8  my ( $wanted, $list ) = find_by_min_size ( MAX_SIZE ) ;
> 9  File::Find::find ( { wanted => $wanted, prune => 
> $File::Find::prune = shift}, $fs ) ;
> 10@large_files = $list->() ;
> 11
> 12@sorted_large_files =
> 13 sort { -s $b <=> -s $a }
> 14@large_files ;
> 15
> 16   } ##-- End sub --##

That's not within your wanted() routine.

File::Find will call your wanted() code many times. Your code will
normally leave prune alone. At some point, your code will find itself
dealing with a directory into which you don't want to search, so your
code will set prune to a true value; this will cause File::Find to say
to itself, "Ho ho! You don't want to go deeper than here! Your wish is
my command!" It will consider that directory to be complete, and go on
to the next, thereby pruning the search tree.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

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




split then match, regex better?

2008-01-09 Thread Kevin Viel
Happy New Year.

I have a series of values with the following form:

TO_Chr10_final.txt

I would like to obtain the value 10, for accounting purposes:

my $chr = ( split /_/ , $value ) [ 1 ] ;
$chr =~ /chr/i ;

$chr = $' ;

This seems convoluted.  Could someone please criticize this approach or
offer a better one?

Thank you,

Kevin


Kevin Viel, PhD
Post-doctoral fellow
Department of Genetics
Southwest Foundation for Biomedical Research
San Antonio, TX 78227 


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




Q: how to push into array

2008-01-09 Thread ciwei
HI, a quetion from a newbie to perl.
I have a program that extract some fields:

#!/usr/bin/perl -w

use strict;

my ( $host, $hba, $storage, $fa ,$initiator , $target ) ;
my %wwn = ();

while (  ) {
 next unless /\s+([A-Z]\w+)[_-](HBA\d)[_-]([A-Z]\w+)[_-](\w+)\s+ ...
WWN: \d\d\d\d\w{12}/;
( $host, $hba, $storage, $fa ) = /\s+([A-Z]\w+)[_-](HBA\d)[_-]([A-Z]\w
+)[_-](\w+)\s+/;

   print "HOST = $host , HBA = $hba , storage = $storage, FA = $fa
\n";

   $initiator = $host."-".$hba;
   $target  = $storage."-".$fa;

   push  $wwn{$initiator}, $1   if /WWN:\s+(1000\d{12})/;
   push  $wwn{$target}   , $1   if /WWN:\s+(500\d{13})/;

}

__DATA__
 DEV01-HBA0_DMX1-13CA
  WWN: 1000C934A35B
  WWN: 5006048ACAFE1E4C
 DEV01_HBA0_CX-SPA_P0
  WWN: 1000C934A35B
  WWN: 500601601060007E
 TEST01_HBA1_STK_TAPES1
  WWN: 10E002239270
  WWN: 500104F000619193
  WWN: 500104F00061918D
  WWN: 500104F000619190
  WWN: 500104F00061919D

when I run it ,  I got

#emc_parse_switch_zone.pl
Type of arg 1 to push must be array (not hash elem) at ./
emc_parse_switch_zone.pl line 20, near "$1 if"
Execution of ./emc_parse_switch_zone.pl aborted due to compilation
errors.

so my questions:
1. what is wrong with push here?
2. how to properly determine the boundaris of the records.  each
record ending with the last "WWN: " lnes.


thanks.
ciwei


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




Re: Q: how to push into array

2008-01-09 Thread Chas. Owens
On Jan 9, 2008 4:12 PM, ciwei <[EMAIL PROTECTED]> wrote:
snip
>push  $wwn{$initiator}, $1   if /WWN:\s+(1000\d{12})/;
>push  $wwn{$target}   , $1   if /WWN:\s+(500\d{13})/;
snip
> Type of arg 1 to push must be array (not hash elem) at ./
> emc_parse_switch_zone.pl line 20, near "$1 if"
> Execution of ./emc_parse_switch_zone.pl aborted due to compilation
> errors.
>
> so my questions:
> 1. what is wrong with push here?
> 2. how to properly determine the boundaris of the records.  each
> record ending with the last "WWN: " lnes.
snip

The push function expects an array not an arrayref, so if you want to
use an arrayref you must first dereference it:
push @{$wwn{$initiator}}, $1   if /WWN:\s+(1000\d{12})/;
push @{$wwn{$target}}   , $1   if /WWN:\s+(500\d{13})/;

I don't understand your second question, could you break your input
into records so we can clearly see what how you want to define the
records?

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




Re: split then match, regex better?

2008-01-09 Thread Chas. Owens
On Jan 9, 2008 1:07 PM, Kevin Viel <[EMAIL PROTECTED]> wrote:
> Happy New Year.
>
> I have a series of values with the following form:
>
> TO_Chr10_final.txt
>
> I would like to obtain the value 10, for accounting purposes:
>
> my $chr = ( split /_/ , $value ) [ 1 ] ;
> $chr =~ /chr/i ;
>
> $chr = $' ;
>
> This seems convoluted.  Could someone please criticize this approach or
> offer a better one?
snip

First off, never use $`, $&, or $', they slow down every regex in your
program.  They are only in modern versions of Perl for backwards
compatibility.  Use captures instead.  You are right that the split is
a waste of effort, just use a better regex:

my ($chr) = $value =~ /_chr(.*)_/i;

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




Re: split then match, regex better?

2008-01-09 Thread John W. Krahn

Kevin Viel wrote:

Happy New Year.

I have a series of values with the following form:

TO_Chr10_final.txt

I would like to obtain the value 10, for accounting purposes:

my $chr = ( split /_/ , $value ) [ 1 ] ;
$chr =~ /chr/i ;

$chr = $' ;

This seems convoluted.  Could someone please criticize this approach or
offer a better one?


my ( $chr ) = $value =~ /_chr(\d+)_/i;



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

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




Re: Q: how to push into array

2008-01-09 Thread John W. Krahn

ciwei wrote:

HI, a quetion from a newbie to perl.
I have a program that extract some fields:

#!/usr/bin/perl -w

use strict;

my ( $host, $hba, $storage, $fa ,$initiator , $target ) ;


It appears that you don't really need those variables in file scope.


my %wwn = ();

while (  ) {
 next unless /\s+([A-Z]\w+)[_-](HBA\d)[_-]([A-Z]\w+)[_-](\w+)\s+ ...
WWN: \d\d\d\d\w{12}/;


That pattern will not match because  reads one line at a time and 
'WWN: \d\d\d\d\w{12}' is on a different line then the rest of the pattern.




( $host, $hba, $storage, $fa ) = /\s+([A-Z]\w+)[_-](HBA\d)[_-]([A-Z]\w
+)[_-](\w+)\s+/;


You don't need to use the same pattern twice:

next unless /^\s+([A-Z]\w+)[_-](HBA\d)[_-]([A-Z]\w+)[_-](\w+)$/;
my ( $host, $hba, $storage, $fa ) = ( $1, $2, $3, $4 );



   print "HOST = $host , HBA = $hba , storage = $storage, FA = $fa
\n";

   $initiator = $host."-".$hba;
   $target  = $storage."-".$fa;

   push  $wwn{$initiator}, $1   if /WWN:\s+(1000\d{12})/;
   push  $wwn{$target}   , $1   if /WWN:\s+(500\d{13})/;


You need to supply an array as the first argument to push().  Also, the 
test is not needed.  And it looks like the digits are hexadecimal so \d 
won't match.


  push @{ $wwn{ "$host-$hba"   } }, /^\s+WWN:\s+(1000[0-9a-fA-F]{12})$/;
  push @{ $wwn{ "$storage-$fa" } }, /^\s+WWN:\s+(500[0-9a-fA-F]{13})$/;



}

__DATA__
 DEV01-HBA0_DMX1-13CA
  WWN: 1000C934A35B
  WWN: 5006048ACAFE1E4C
 DEV01_HBA0_CX-SPA_P0
  WWN: 1000C934A35B
  WWN: 500601601060007E
 TEST01_HBA1_STK_TAPES1
  WWN: 10E002239270
  WWN: 500104F000619193
  WWN: 500104F00061918D
  WWN: 500104F000619190
  WWN: 500104F00061919D



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

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




Re: print a selection of a file

2008-01-09 Thread Rob Dixon

[EMAIL PROTECTED] wrote:

Hello,

I try  to  print (get)  a specific text selection from  a  text file,
but  I don't know  how to  do  it:
What I try  todo  is  to open a  file search  a string and  print
the  follow lines from that  string until he found  a white line. then
he need to stop.  so can i  get  the  lines (strings) that i need.

#!/opt/perl/bin/perl  -w
use  strict;

#variable

my @horcm_file;


sub  readdata{
  open(HORCM, "/etc/horcm10.conf") || die  ("File error");
  @horcm_file = ;
  chomp(@horcm_file);
  close(HORCM);
  return(@horcm_file);
}

my @pipo=readdata();

foreach (@pipo){
  /HORCM_INST/ or next;
  print;
}


use strict;
use warnings;

open my $fh, '/etc/horcm10.conf' or die $!;

while (<$fh>) {
  next unless /HORCM_INST/ .. not /\S/;
  print;
}



Rob

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




Re: More installing modules issues - using a local directory

2008-01-09 Thread yitzle
Done.
Thanks!

On Jan 9, 2008 5:11 PM, Tom Phoenix <[EMAIL PROTECTED]> wrote:
> On Jan 9, 2008 1:38 PM, yitzle <[EMAIL PROTECTED]> wrote:
>
> > I installed LWP manually into a local directory (~/perl)
> > When I try to install WWW::Mechanize, it finds the old version - not
> > the new local version - and fails.
>
> The new version needs to be the first one found by looking in the @INC
> directories, but your @INC probably doesn't include the local
> directory. You probably want to set the PERL5LIB environment variable.
> When I need this sort of thing, I put something like this in my
> ~/.bash_profile, so that it takes effect automatically in each new
> shell; your shell may require different syntax, and your path may need
> to be different:
>
>export PERL5LIB=~/perl/
>
> When perl starts running, it will normally add the directories in
> PERL5LIB to the start of @INC before it starts compiling your program,
> resembling what would happen if each program had a 'use lib' line
> added near the top. Using the correct path should allow the
> installation program to find the right module.
>
> Good luck with it!
>
> --Tom Phoenix
> Stonehenge Perl Training
>

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




Re: split then match, regex better?

2008-01-09 Thread oryann9
Happy New Year.

I have a series of values with the following form:

TO_Chr10_final.txt

I would like to obtain the value 10, for accounting purposes:

my $chr = ( split /_/ , $value ) [ 1 ] ;
$chr =~ /chr/i ;

$chr = $' ;

This seems convoluted.  Could someone please criticize this approach or
offer a better one?
-

yes there is many ways, but I like this one.

$ perl -le 'my $str=qq(TO_Chr10_final.txt); my @arr = unpack("A2" x 
(length($str) >> 1), $str); print grep {/^\d+$/} @arr;'
10

Does that help?
: )





  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 


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