Re: run command in a particular dir

2007-01-09 Thread Mumia W.

On 01/09/2007 12:49 AM, [EMAIL PROTECTED] wrote:

Hi,
I need to run a particular command  "cleartool des " from a partiuclar
folder.
For example:
I need to get into directory m: cd \ Arun_Main and then run cleartool des
$temp .

I wrote the following code for this

foreach $temp(@vob2)
{
qx(m: cd \\Arun_Main);
$x = qx(cleartool des $temp);
$hash{$temp} = $x;
}

I ran this code from command prompt c:

But the above code seems to act the following way:
It goes into dir Arun_Main in line 3. But comes back to c: in line 4 and
tries to run the command cleartool des $temp from c: instead of m: cd
\\Arun_Main.

Can anyone please help me out to sort this problem ?

[...]


Try this:

use Cwd;
my $oldpwd = getcwd();
chdir "m:/Arun_Main";

foreach my $temp (@vob2)
{
my $x = qx(cleartool des $temp);
$hash{$temp} = $x;
}

chdir $oldpwd;

-
Read the docs:
perldoc -f chdir
perldoc Cwd





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




Video and perl

2007-01-09 Thread Herman Gerritsen

Hi there,

This is my first post on any perl mailinglist.
I have been learning perl lately using Oreilly's "Learning Perl 4th edition"
I am now going through "Intermediate perl".

for my graduation I am trying to write a progam that will read data from the
serial port (/dev/ttyS*). This data is coming from four weight sensors in a
fource plate. In the mean time I want to make some video recording of what
happens on the force plate. With that data I will be able to link the
movement of the center of gravity to whatever happens on the force plate.

I can already read the data from the serial port. But I dont understand how
to capture video (or some images) via an usb camera.
I have been searching to CPAN and have the Device::USB module installed. but
haven't found any tutorial or information on how to get video from a camera.
I don't need many frames a second (somewhere between 3 to 5 frames a second
should suffice) so I think a webcam is already good enough for me.

hopefully someone can direct me in the right direction.

Thanks already
Herman Gerritsen


perl and network connection

2007-01-09 Thread Tatiana Lloret Iglesias

Hi all,
i'm developping a perl script which uses WWW-Mechanize and performs a big
number of  submit_form
I've noticed that because of the execution of this script network connection
fails intermitently ...
how can i avoid this?
Thanks
T.


installing question

2007-01-09 Thread Jorge Almeida

I just installed Perl from source. My distribution (gentoo linux)
supports Perl, of course, but not every module is supported, and I
didn't want to end up with a mixture of supported/hand-compiled modules.

So, I chose /usr/local/opt/perl to keep all Perl things. When using
./Configure, I chose the directory /usr/local/opt/perl/modules for
modules, although I don't really know what this config choice entails.
I installed a few modules, and they didn't end up in
/usr/local/opt/perl/modules, but rather in /usr/local/opt/perl (because
I used /usr/local/opt/perl as --prefix). I would appreciate some
clarification about the "modules" option in Perl's configuration, but
it's not really a big problem.

The problem is:
$ perldoc -f shift
sh: /usr/local/opt/perl/bin/pod2man: /usr/local/perl/bin/perl: bad 
interpreter: No such file or directory
Got a 0-length file from /tmp/VvSvft3UJp via Pod::Perldoc::ToMan!?

Of course, the first line in /usr/local/opt/perl/bin/pod2man is 
#!/usr/local/perl/bin/perl
when it should be 
#!/usr/local/opt/perl/bin/perl


Why is this? I suppose I made some configuration error, but can't
guess which. (I know I can solve the problem by creating a symlink
/usr/local/perl to /usr/local/opt/perl, but I would like to know what
went wrong.)


--
Jorge Almeida

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




regex to split whitespace-separated values

2007-01-09 Thread Bram Kuijper

Hi all,

this is a real beginner question, but I don't seem to find a good solution:

I have a single line of whitespace separated values, e.g.:

  50 100 
150 200   300 50


Now I want to split these values into an array using split, like:

my @array = split(/\s+/,$line);

but, unfortunately, the first value in the array is now an empty value. 
I can of course shift this value from the array, but I believe there 
must be a more elegant solution to this.


So I thought about using a positive look-behind assertion in which I 
look for any number preceded by a whitespace, e.g. something like:


my @array = split(/\d+(?<=\s+)/,$line);

but perl will only accept fixed-width values for look-behind assertions.

Anyone any ideas?

cheers,
Bram





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




test

2007-01-09 Thread Sayed, Irfan \(Irfan\)
test


Re: regex to split whitespace-separated values

2007-01-09 Thread Ovid
--- Bram Kuijper <[EMAIL PROTECTED]> wrote:

> I have a single line of whitespace separated values, e.g.:
> 
>50 100 
> 150 200   300 50
> 
> Now I want to split these values into an array using split, like:
> 
> my @array = split(/\s+/,$line);
> 
> but, unfortunately, the first value in the array is now an empty
> value. 

A little known feature of 'split' is that if you call split without
arguments, it automatically splits on whitespace in $_, trimming
extraneous whitespace.

  #!/usr/bin/perl 

  use strict;
  use warnings;
  use Data::Dumper;

  my $line = '   50 100 
  150 200   300 50';

  my @array = do { local $_ = $line; split };
  print Dumper [EMAIL PROTECTED];

That prints:

  $VAR1 = [
'50',
'100',
'150',
'200',
'300',
'50'
  ];

Cheers,
Ovid

--

Buy the book -- http://www.oreilly.com/catalog/perlhks/
Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/

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




Re: installing question

2007-01-09 Thread Arvind Autar

gentoo is a bad distrobution you should remove it and install a sane
distrobution.


Yours truly



2007/1/9, Jorge Almeida <[EMAIL PROTECTED]>:


I just installed Perl from source. My distribution (gentoo linux)
supports Perl, of course, but not every module is supported, and I
didn't want to end up with a mixture of supported/hand-compiled modules.

So, I chose /usr/local/opt/perl to keep all Perl things. When using
./Configure, I chose the directory /usr/local/opt/perl/modules for
modules, although I don't really know what this config choice entails.
I installed a few modules, and they didn't end up in
/usr/local/opt/perl/modules, but rather in /usr/local/opt/perl (because
I used /usr/local/opt/perl as --prefix). I would appreciate some
clarification about the "modules" option in Perl's configuration, but
it's not really a big problem.

The problem is:
$ perldoc -f shift
sh: /usr/local/opt/perl/bin/pod2man: /usr/local/perl/bin/perl: bad
interpreter: No such file or directory
Got a 0-length file from /tmp/VvSvft3UJp via Pod::Perldoc::ToMan!?

Of course, the first line in /usr/local/opt/perl/bin/pod2man is
#!/usr/local/perl/bin/perl
when it should be
#!/usr/local/opt/perl/bin/perl

Why is this? I suppose I made some configuration error, but can't
guess which. (I know I can solve the problem by creating a symlink
/usr/local/perl to /usr/local/opt/perl, but I would like to know what
went wrong.)


--
Jorge Almeida

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





Re: test

2007-01-09 Thread Matt Richards
On Tue, 2007-01-09 at 18:45 +0800, Sayed, Irfan (Irfan) wrote:
> test

it works :)



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




Re: test

2007-01-09 Thread Matt Richards
On Tue, 2007-01-09 at 18:45 +0800, Sayed, Irfan (Irfan) wrote:
> test

it works :)



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




Re: installing question

2007-01-09 Thread Jorge Almeida

On Tue, 9 Jan 2007, Arvind Autar wrote:


gentoo is a bad distrobution you should remove it and install a sane
distrobution.


I will follow your suggestion, of course. What brand of Windows do you
favor?
--
Jorge Almeida

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




Re: installing question

2007-01-09 Thread Matt
And this answers his question exactly how?

Mathew

Arvind Autar <[EMAIL PROTECTED]> wrote: gentoo is a bad distrobution you should 
remove it and install a sane
distrobution.


Yours truly



2007/1/9, Jorge Almeida :
>
> I just installed Perl from source. My distribution (gentoo linux)
> supports Perl, of course, but not every module is supported, and I
> didn't want to end up with a mixture of supported/hand-compiled modules.
>
> So, I chose /usr/local/opt/perl to keep all Perl things. When using
> ./Configure, I chose the directory /usr/local/opt/perl/modules for
> modules, although I don't really know what this config choice entails.
> I installed a few modules, and they didn't end up in
> /usr/local/opt/perl/modules, but rather in /usr/local/opt/perl (because
> I used /usr/local/opt/perl as --prefix). I would appreciate some
> clarification about the "modules" option in Perl's configuration, but
> it's not really a big problem.
>
> The problem is:
> $ perldoc -f shift
> sh: /usr/local/opt/perl/bin/pod2man: /usr/local/perl/bin/perl: bad
> interpreter: No such file or directory
> Got a 0-length file from /tmp/VvSvft3UJp via Pod::Perldoc::ToMan!?
>
> Of course, the first line in /usr/local/opt/perl/bin/pod2man is
> #!/usr/local/perl/bin/perl
> when it should be
> #!/usr/local/opt/perl/bin/perl
>
> Why is this? I suppose I made some configuration error, but can't
> guess which. (I know I can solve the problem by creating a symlink
> /usr/local/perl to /usr/local/opt/perl, but I would like to know what
> went wrong.)
>
>
> --
> Jorge Almeida
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>



--
If a documentary were made about undocumented immigrants, would it solve their 
problem?

www.theillien.com

Re: installing question

2007-01-09 Thread Arvind Autar

debian.

Gentoo has a whole history of open source distrobuters who boycot it. Check
out 'gaim' for example.

2007/1/9, Jorge Almeida <[EMAIL PROTECTED]>:


On Tue, 9 Jan 2007, Arvind Autar wrote:

> gentoo is a bad distrobution you should remove it and install a sane
> distrobution.
>
I will follow your suggestion, of course. What brand of Windows do you
favor?
--
Jorge Almeida



Re: regex to split whitespace-separated values

2007-01-09 Thread Rob Dixon

Ovid wrote:
> --- Bram Kuijper <[EMAIL PROTECTED]> wrote:
>
>> I have a single line of whitespace separated values, e.g.:
>>
>>50 100
>> 150 200   300 50
>>
>> Now I want to split these values into an array using split, like:
>>
>> my @array = split(/\s+/,$line);
>>
>> but, unfortunately, the first value in the array is now an empty
>> value.
>
> A little known feature of 'split' is that if you call split without
> arguments, it automatically splits on whitespace in $_, trimming
> extraneous whitespace.
>
>   #!/usr/bin/perl
>
>   use strict;
>   use warnings;
>   use Data::Dumper;
>
>   my $line = '   50 100
>   150 200   300 50';
>
>   my @array = do { local $_ = $line; split };
>   print Dumper [EMAIL PROTECTED];

[snip]

The default behaviour can be invoked explicitly by using a single space as the
separator parameter for split. So

my @array = split ' ', $line;

has the desired effect.

Note that this must be a single-space /string/, not a regular expression.

HTH,

Rob

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




Re: Checking for infinite loops

2007-01-09 Thread hOURS
Thanks.  I did change the longRunningModule part.  The syntax error was in the 
line:
  if ($@) {
  apparently at the end of the line, which I believe usually means opening 
brackets without closing brackets or vice versa.
  
  Fred

Jay Savage <[EMAIL PROTECTED]> wrote:  On 1/8/07, hOURS  wrote:
> Hi everyone,
>  Jay offered me the following code to help with something. I don't  undertand 
> it, but tried to use it anyway to see if it would work. The  computer told me 
> there was a syntax error in the area I highlighted in  color. I can't find it 
> - maybe that's because I don't understand the  code fully, but if anyone can 
> show me where it is I'd be grateful.
>   Thanks,
>   Fred Kittelmann
>
> Jay Savage  wrote:my $timeout = 3600; # 1 hour
> eval {
> local $SIG{ALRM} = sub { die "longRunningModule timed out\n" };
> alarm $timeout;
> require longRunningModule;
> alarm 0;
> }
>
> if ($@) {
> if ($@ =~ /timed out/) {
> # timeout
> } else {
> # some other error
> }
> }
>
>
>
> Fred Kittelmann

Fred,

Most people on this list probably don't accept HTML emails from it--I
know I don't--so it's unclear what you highlighted in color.

My guess, though, is that you don't actually have a perl module named
'longRunningModule'. That's just the placeholder the perldoc uses. you
need to replace that with whatever bit of code you're trying to
timeout. The code from the perldoc is generic; you need to make it fit
your situation.

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.downloadsquad.com  http://www.engatiki.org

values of â will give rise to dom!


 __
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

%Re: installing question

2007-01-09 Thread David Gama Rodriguez
Hi all,

I read this post and I'm concern.
why are you saying  gentoo is a bad distribution, I dont want to start a
fight to know which distribution is the best that is not the point.
I just want to know why this:

"has a whole history of open source distrobuters who boycot it. Check
out 'gaim' for example"

And why Jorge say "what brand of windows do you favor?" , I mean
windows?? really???

Greetings!!

El mar, 09-01-2007 a las 13:08 +0100, Arvind Autar escribió:
> debian.
> 
> Gentoo has a whole history of open source distrobuters who boycot it. Check
> out 'gaim' for example.
> 
> 2007/1/9, Jorge Almeida <[EMAIL PROTECTED]>:
> >
> > On Tue, 9 Jan 2007, Arvind Autar wrote:
> >
> > > gentoo is a bad distrobution you should remove it and install a sane
> > > distrobution.
> > >
> > I will follow your suggestion, of course. What brand of Windows do you
> > favor?
> > --
> > Jorge Almeida
> >

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




Re: %Re: installing question

2007-01-09 Thread Mathew
I don't know anything about Gentoo nor do I care about a debate
regarding it.  I think the Windows comment though was a simply a clever
retort to a pointless post.

Mathew

David Gama Rodriguez wrote:
> Hi all,
> 
> I read this post and I'm concern.
> why are you saying  gentoo is a bad distribution, I dont want to start a
> fight to know which distribution is the best that is not the point.
> I just want to know why this:
> 
> "has a whole history of open source distrobuters who boycot it. Check
> out 'gaim' for example"
> 
> And why Jorge say "what brand of windows do you favor?" , I mean
> windows?? really???
> 
> Greetings!!
> 
> El mar, 09-01-2007 a las 13:08 +0100, Arvind Autar escribió:
>> debian.
>>
>> Gentoo has a whole history of open source distrobuters who boycot it. Check
>> out 'gaim' for example.
>>
>> 2007/1/9, Jorge Almeida <[EMAIL PROTECTED]>:
>>> On Tue, 9 Jan 2007, Arvind Autar wrote:
>>>
 gentoo is a bad distrobution you should remove it and install a sane
 distrobution.

>>> I will follow your suggestion, of course. What brand of Windows do you
>>> favor?
>>> --
>>> Jorge Almeida
>>>
> 


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




Re: regex to split whitespace-separated values

2007-01-09 Thread Ovid
--- Rob Dixon <[EMAIL PROTECTED]> wrote:
 
> The default behaviour can be invoked explicitly by using a single
> space as the
> separator parameter for split. So
> 
> my @array = split ' ', $line;
> 
> has the desired effect.

Ah, thank you.  I didn't know that :)

Cheers,
Ovid

--

Buy the book -- http://www.oreilly.com/catalog/perlhks/
Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/

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




% installing question

2007-01-09 Thread David Gama Rodriguez

Ok ok, 

Reading all the thread, I'd like to comment that maybe Jaime problem is
that he must uninstall the perl version that came with gentoo: 

emerge --unmerge perl

and then install perl with his own configuration maybe that will work

Greetings


El mar, 09-01-2007 a las 10:14 -0500, Mathew escribió:
> I don't know anything about Gentoo nor do I care about a debate
> regarding it.  I think the Windows comment though was a simply a clever
> retort to a pointless post.
> 
> Mathew
> 
> David Gama Rodriguez wrote:
> > Hi all,
> > 
> > I read this post and I'm concern.
> > why are you saying  gentoo is a bad distribution, I dont want to start a
> > fight to know which distribution is the best that is not the point.
> > I just want to know why this:
> > 
> > "has a whole history of open source distrobuters who boycot it. Check
> > out 'gaim' for example"
> > 
> > And why Jorge say "what brand of windows do you favor?" , I mean
> > windows?? really???
> > 
> > Greetings!!
> > 
> > El mar, 09-01-2007 a las 13:08 +0100, Arvind Autar escribió:
> >> debian.
> >>
> >> Gentoo has a whole history of open source distrobuters who boycot it. Check
> >> out 'gaim' for example.
> >>
> >> 2007/1/9, Jorge Almeida <[EMAIL PROTECTED]>:
> >>> On Tue, 9 Jan 2007, Arvind Autar wrote:
> >>>
>  gentoo is a bad distrobution you should remove it and install a sane
>  distrobution.
> 
> >>> I will follow your suggestion, of course. What brand of Windows do you
> >>> favor?
> >>> --
> >>> Jorge Almeida
> >>>
> > 
> 

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




Re: Video and perl

2007-01-09 Thread Herman Gerritsen

I  have been looking on the ffmpeg website and found the FFmpeg perl module.
I think it is a good option.
I presume the FFmpeg module gives me a faster interface than if I call the
ffmpeg with the system command?

Thanks for the fast responses
Herman

On 1/9/07, Mike Martin <[EMAIL PROTECTED]> wrote:


On 09/01/07, Herman Gerritsen <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> This is my first post on any perl mailinglist.
> I have been learning perl lately using Oreilly's "Learning Perl 4th
edition"
> I am now going through "Intermediate perl".
>
> for my graduation I am trying to write a progam that will read data from
the
> serial port (/dev/ttyS*). This data is coming from four weight sensors
in a
> fource plate. In the mean time I want to make some video recording of
what
> happens on the force plate. With that data I will be able to link the
> movement of the center of gravity to whatever happens on the force
plate.
>
> I can already read the data from the serial port. But I dont understand
how
> to capture video (or some images) via an usb camera.
> I have been searching to CPAN and have the Device::USB module installed.
but
> haven't found any tutorial or information on how to get video from a
camera.
> I don't need many frames a second (somewhere between 3 to 5 frames a
second
> should suffice) so I think a webcam is already good enough for me.
>
> hopefully someone can direct me in the right direction.
>
> Thanks already
> Herman Gerritsen
>
>
Why not use a system command to soemthing like ffmpeg
eg: system("ffmpeg -vd /dev/ ")



Re: Checking for infinite loops

2007-01-09 Thread Dave Gray

On 1/8/07, hOURS <[EMAIL PROTECTED]> wrote:

Hi everyone,
  Jay offered me the following code to help with something.  I don't  undertand 
it, but tried to use it anyway to see if it would work.   The computer told me 
there was a syntax error in the area I highlighted  in color.  I can't find it 
- maybe that's because I don't  understand the code fully, but if anyone can 
show me where it is I'd be  grateful.

Jay Savage <[EMAIL PROTECTED]> wrote:my $timeout = 3600; # 1 hour
eval {
local $SIG{ALRM} = sub { die "longRunningModule timed out\n" };
alarm $timeout;
require longRunningModule;
alarm 0;
}


in case this isn't fixed yet, eval blocks need to be ended with a
semicolon, like eval { };

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




HoHoH

2007-01-09 Thread oryann9
I have a HoHoH structure that looks like after running print Dumper (\%hash);
   
'prlhNSSA' => {
  '1499' => {
  'gecos' => 'First Name Last 
Name,CIS,location,
  'host' => '/var/tmp/passwd.tgpdrpp1.hpux',
  'gid' => '205'
}
}
};

   
  My 1st hash is keyed by name, that accesses 2nd hash keyed by UID,  that 
accesses a 3rd hash keyed by remaining items: gid,gecos and hostname.
   
   The snippet of code is: 
   
  my %hash;
  my ($name, $uid, $gid, $gecos);
  my $regexp= qr/(\w+|\w+\.\w+|\w+\-\w+|\w+\_\w+)\s+(\d+)\s+(\d+)\s+(.*)/i ;
  ...
  ...
  elsif (/$regexp/) {
  ($name, $uid, $gid, $gecos) = ($1, $2, $3, $4);
$hash{$name}{$uid} = { # User data keyed by uid
gid => $gid,
gecos => $gecos,
host=> $host,

  my question is how do I access and print all values? I am trying:
   
  foreach  (keys %dub_hash) {
print %{$dub_hash->{$name}->{$uid}->{%gid}->{$gecos} };
}

  Do I need three loops? What am I doing wrong?
   
  thank you
  
 
   
   

 __
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: %Re: installing question

2007-01-09 Thread Jorge Almeida

On Tue, 9 Jan 2007, Mathew wrote:


regarding it.  I think the Windows comment though was a simply a clever
retort to a pointless post.


Yes, it was a simple sarcasm. It seems that both the sarcasm and the
irony preceeding it were lost on the intended destinatary. Let's forget
it.
Still, I apologize if my comment offended someone. My despise for
Windows doesn't extend to people using it, and certainly not to those
who are also Perl users.

Cheers.
--
Jorge Almeida

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




Re: % installing question

2007-01-09 Thread Jorge Almeida

On Tue, 9 Jan 2007, David Gama Rodriguez wrote:



Reading all the thread, I'd like to comment that maybe Jaime problem is
that he must uninstall the perl version that came with gentoo:


That would probably be a bad idea, as Perl is essential to gentoo. And I
don't think there is a problem with having two Perls in the same box.
After all, the Perl Configure script is civilized: it detected the
original perl binary /usr/bin/perl and asked whether I would like to
have it replaced by the new one (which I didn't, of course).

Anyway, my setup works, as far as I can tell. The problem I mentioned is
either something very obvious for people who usually install from source
or else some detail in the developers league.

The symlink workaround does the job, but I still would like to know
whether I did something wrong...

Cheers.
--
Jorge Almeida

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




Re: HoHoH

2007-01-09 Thread Dave Gray

On 1/9/07, oryann9 <[EMAIL PROTECTED]> wrote:

I have a HoHoH structure that looks like after running print Dumper (\%hash);

'prlhNSSA' => {
  '1499' => {
  'gecos' => 'First Name Last 
Name,CIS,location,
  'host' => '/var/tmp/passwd.tgpdrpp1.hpux',
  'gid' => '205'
}
}
};


  My 1st hash is keyed by name, that accesses 2nd hash keyed by UID,  that 
accesses a 3rd hash keyed by remaining items: gid,gecos and hostname.

[snip]

  my question is how do I access and print all values? I am trying:

  foreach  (keys %dub_hash) {
print %{$dub_hash->{$name}->{$uid}->{%gid}->{$gecos} };
}

  Do I need three loops? What am I doing wrong?


Yup, three loops. I'll get you started:

 for my $name (keys %dub_hash) {
   for my $uid (keys %{$dub_hash{$name}}) {
 # do stuff, note the %{...} above to force precedence
   }
 }

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




Re: HoHoH

2007-01-09 Thread John W. Krahn
oryann9 wrote:
> I have a HoHoH structure that looks like after running print Dumper (\%hash);
> 
> 'prlhNSSA' => {
> '1499' => {
> 'gecos' => 'First Name Last Name,CIS,location,
> 'host' => '/var/tmp/passwd.tgpdrpp1.hpux',
> 'gid' => '205'
> }
> }
> };
> 
> 
> My 1st hash is keyed by name, that accesses 2nd hash keyed by UID,  that
> accesses a 3rd hash keyed by remaining items: gid,gecos and hostname.
> 
> The snippet of code is: 
> 
> my %hash;
> my ($name, $uid, $gid, $gecos);
> my $regexp= qr/(\w+|\w+\.\w+|\w+\-\w+|\w+\_\w+)\s+(\d+)\s+(\d+)\s+(.*)/i ;
> ...
> ...
> elsif (/$regexp/) {
> ($name, $uid, $gid, $gecos) = ($1, $2, $3, $4);
>   $hash{$name}{$uid} = { # User data keyed by uid
>   gid => $gid,
>   gecos => $gecos,
>   host=> $host,
> 
> my question is how do I access and print all values? I am trying:
> 
> foreach  (keys %dub_hash) {
>   print %{$dub_hash->{$name}->{$uid}->{%gid}->{$gecos} };
> }
> 
> Do I need three loops? What am I doing wrong?

Yes, you need three loops:

$ perl -le'
my %hash = (
prlhNSSA => {
1499 => {
gecos => "First Name Last Name,CIS,location",
host  => "/var/tmp/passwd.tgpdrpp1.hpux",
gid   => 205,
},
},
);

for my $name ( keys %hash ) {
for my $uid ( keys %{ $hash{ $name } } ) {
for my $key ( keys %{ $hash{ $name }{ $uid } } ) {
print $hash{ $name }{ $uid }{ $key };
}
}
}
'
First Name Last Name,CIS,location
205
/var/tmp/passwd.tgpdrpp1.hpux


Or, since you just want the values:

$ perl -le'
my %hash = (
prlhNSSA => {
1499 => {
gecos => "First Name Last Name,CIS,location",
host  => "/var/tmp/passwd.tgpdrpp1.hpux",
gid   => 205,
},
},
);

for my $uid ( values %hash ) {
for my $hash ( values %$uid ) {
for my $val ( values %$hash ) {
print $val;
}
}
}
'
First Name Last Name,CIS,location
205
/var/tmp/passwd.tgpdrpp1.hpux



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: HoHoH

2007-01-09 Thread oryann9


  
> my question is how do I access and print all values? I am trying:
>
> foreach (keys %dub_hash) {
> print %{$dub_hash->{$name}->{$uid}->{%gid}->{$gecos} };
> }
>
> Do I need three loops? What am I doing wrong?

Yup, three loops. I'll get you started:

for my $name (keys %dub_hash) {
for my $uid (keys %{$dub_hash{$name}}) {
# do stuff, note the %{...} above to force precedence
}
}
  Ok thank you!  So if I have a HoHoHoH I would need 4 loops and so on?
  Is there a good tutorial for hashes with real world examples b/c I seem to 
struggle with comples data structures as the above took me longer than expected.


 __
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: HoHoH

2007-01-09 Thread John W. Krahn
Dave Gray wrote:
> 
> Yup, three loops. I'll get you started:
> 
>  for my $name (keys %dub_hash) {
>for my $uid (keys %{$dub_hash{$name}}) {
>  # do stuff, note the %{...} above to force precedence

Parentheses () are used for precedence, %{} dereferences the reference
contained in $dub_hash{$name}

>}
>  }


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/




Reading a files in a folder

2007-01-09 Thread Geetha Weerasooriya
Hi ,
 
I have data files which are in different folders. I want to run the same
program on all the data files. For example I have 12 folders for 12
months of the year and each folder contains the files for each day of
the month. So one file contains 30 or 31 files. 
 
Can some one kindly guide me to do this? Or can you give any reference
material to study this type of data handling?
 
Thanks in advance.
 
Best wishes,
 
Geetha


Re: Reading a files in a folder

2007-01-09 Thread John W. Krahn
Geetha Weerasooriya wrote:
> Hi ,

Hello,

> I have data files which are in different folders. I want to run the same
> program on all the data files. For example I have 12 folders for 12
> months of the year and each folder contains the files for each day of
> the month. So one file contains 30 or 31 files. 

or 28 or 29 files.

> Can some one kindly guide me to do this? Or can you give any reference
> material to study this type of data handling?

It sounds like a fairly simple directory structure.  What are you having
problems with?


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/




remove duplicate lines

2007-01-09 Thread beast

I have these following data:

a 100
a 102
c 100
a 102
b 111
c 100
c 102
c 100
c 100
a 102
...

I would like to have a list (either array or hash) with unique line . 
Any help would appreciated.

Thanks.



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




Re: remove duplicate lines

2007-01-09 Thread Mathew Snyder
beast wrote:
> I have these following data:
> 
> a 100
> a 102
> c 100
> a 102
> b 111
> c 100
> c 102
> c 100
> c 100
> a 102
> ...
> 
> I would like to have a list (either array or hash) with unique line .
> Any help would appreciated.
> Thanks.
> 
> 
> 
The way I would do it is to place the initial data instance into a hash if it
doesn't already exist.

Just do a next if it does.

Mathew

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




Re: remove duplicate lines

2007-01-09 Thread beast

Mathew Snyder wrote:

The way I would do it is to place the initial data instance into a hash if it
doesn't already exist.

Just do a next if it does.
  


It will remove duplicate key, not line.

my %hash=();

while (<>) {
  chomp;
  my ($key, $val) = split /,/;
  $hash{$key} = $val;
}

while ( my ($key, $value) = each(%h) ) {
  print "$key => $value\n";
}


Thanks.


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




Re: remove duplicate lines

2007-01-09 Thread Owen Cook
On Wed, Jan 10, 2007 at 12:47:25PM +0700, beast wrote:
> I have these following data:
> 
> a 100
> a 102
> c 100
> a 102
> b 111
> c 100
> c 102
> c 100
> c 100
> a 102
> ...
> 
> I would like to have a list (either array or hash) with unique line . 
> Any help would appreciated.
> Thanks.
> 


1. You need to read the data
2. You need to split it into its components
3. Then create a hash with the component

This is untested off top of head

my %data_hash;

while(){
chomp;  # Get rid of line feeds
my @bits = split;
$data_hash{$bits[0]} = $bits[1];
}

foreach my $data(keys %data_hash){print "$data $data_hash{$data}\n" }



Owen




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




Re: remove duplicate lines

2007-01-09 Thread beast

Owen Cook wrote:

my %data_hash;

while(){
chomp;  # Get rid of line feeds
my @bits = split;
$data_hash{$bits[0]} = $bits[1];
}
  


It will only remove duplicate key.

Is this still acceptable in perl (its very ugly =(

while (<>) {
  chomp;
  my ($k, $v) = split /,/;
  my $tmp_key = $k . "_" . $v;
  $hash{$tmp_key} = $_;
}

foreach $key (sort(keys %hash)) {
  my ($k, $v) = split /_/, $key;
  print  "$k => $v\n";
}



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