anonymous array for loop

2013-03-09 Thread Chris Stinemetz
Thank you in advance.

Each anonymous array @files and @newFiles has 5 total elements.

How can I alter this nested for so that just the unique elements are
printed instead of each element twice?

foreach my $file (@files) {
  foreach my $newFileName ( @newFiles ) {
  print join( \t, @$file, @$newFileName ), \n;
#  $ftp-put(@$file,@$newFileName) || die can't put file: @$file $!;
  }
}


## output ##

/storage/pcmd/2013-03-09.06:17.-0700.MMEpcmd.gz
2013-03-09.06_17.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:17.-0700.MMEpcmd.gz
2013-03-09.06_22.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:17.-0700.MMEpcmd.gz
2013-03-09.06_19.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:17.-0700.MMEpcmd.gz
2013-03-09.06_21.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:17.-0700.MMEpcmd.gz
2013-03-09.06_20.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:17.-0700.MMEpcmd.gz
2013-03-09.06_18.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:22.-0700.MMEpcmd.gz
2013-03-09.06_17.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:22.-0700.MMEpcmd.gz
2013-03-09.06_22.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:22.-0700.MMEpcmd.gz
2013-03-09.06_19.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:22.-0700.MMEpcmd.gz
2013-03-09.06_21.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:22.-0700.MMEpcmd.gz
2013-03-09.06_20.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:22.-0700.MMEpcmd.gz
2013-03-09.06_18.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:19.-0700.MMEpcmd.gz
2013-03-09.06_17.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:19.-0700.MMEpcmd.gz
2013-03-09.06_22.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:19.-0700.MMEpcmd.gz
2013-03-09.06_19.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:19.-0700.MMEpcmd.gz
2013-03-09.06_21.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:19.-0700.MMEpcmd.gz
2013-03-09.06_20.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:19.-0700.MMEpcmd.gz
2013-03-09.06_18.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:21.-0700.MMEpcmd.gz
2013-03-09.06_17.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:21.-0700.MMEpcmd.gz
2013-03-09.06_22.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:21.-0700.MMEpcmd.gz
2013-03-09.06_19.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:21.-0700.MMEpcmd.gz
2013-03-09.06_21.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:21.-0700.MMEpcmd.gz
2013-03-09.06_20.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:21.-0700.MMEpcmd.gz
2013-03-09.06_18.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:20.-0700.MMEpcmd.gz
2013-03-09.06_17.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:20.-0700.MMEpcmd.gz
2013-03-09.06_22.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:20.-0700.MMEpcmd.gz
2013-03-09.06_19.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:20.-0700.MMEpcmd.gz
2013-03-09.06_21.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:20.-0700.MMEpcmd.gz
2013-03-09.06_20.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:20.-0700.MMEpcmd.gz
2013-03-09.06_18.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:18.-0700.MMEpcmd.gz
2013-03-09.06_17.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:18.-0700.MMEpcmd.gz
2013-03-09.06_22.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:18.-0700.MMEpcmd.gz
2013-03-09.06_19.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:18.-0700.MMEpcmd.gz
2013-03-09.06_21.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:18.-0700.MMEpcmd.gz
2013-03-09.06_20.-0700.MMEpcmd.gz
/storage/pcmd/2013-03-09.06:18.-0700.MMEpcmd.gz
2013-03-09.06_18.-0700.MMEpcmd.gz


Re: anonymous array for loop

2013-03-09 Thread Chris Stinemetz
Never mind, I got it.

I was over thinking it.

I just created one anonymous array with the elements I wanted then used the
following loop.

foreach my $file (@files) {
  print join( \t, @$file[0], @$file[1] ), \n;
  $ftp-put(@$file[0], @$file[1]) || die can't put files: @$file[0] \t
@$file[1] $!;
}


Thanks,

Chris


Re: anonymous array for loop

2013-03-09 Thread Chris Stinemetz
On Sat, Mar 9, 2013 at 2:57 PM, Brandon McCaig bamcc...@gmail.com wrote:

 On Sat, Mar 09, 2013 at 07:24:37AM -0600, Chris Stinemetz wrote:
  Each anonymous array @files and @newFiles has 5 total elements.

 Just to nitpick, @files and @newFiles are not anonymous arrays.
 They are just arrays. They have names. You cannot have anonymous
 arrays in Perl except by reference. That is, [] gives you a
 reference to an anonymous array.

   my @named_array = (1,2,3);
   my $anon_array_ref = [1,2,3];
   my @named_array_copy_of_anon_array = @$anon_array_ref;

 Regards,



I don't think that is true.

Example being:

#!/usr/bin/perl
use warnings;
use strict;

use Data::Dumper;

my $firstVar = One;
my $secondVar = Two;

my @array;
push @array,[$firstVar, $secondVar];

print Dumper \@array;

for my $item ( @array ) {
  print join(\t, @$item[0], @$item[1]), \n;
}


## output ##

$VAR1 = [
  [
'One',
'Two'
  ]
];
One Two


-Chris


Net::FTP

2013-03-08 Thread Chris Stinemetz
U
sing Net::FTP is there a way to rename a file after locating it and before
putting it?

For example:

 $ftp-put('/storage/pcmd/2013-03-08.17:21.-0700.MMEpcmd.gz') || die can't
put file: $!;

Doesn't transfer correctly because the windows FTP server doesn't allow :
in the file name.

Any help is appreciated.

Thank you,

Chris


large files

2013-03-05 Thread Chris Stinemetz
Hello List,

I am working on a script to parse large files, by large I mean 4 million
line+ in length and when splitting on the delimiter ( ; ) there are close
to 300 fields per record, but I am only interested in the first 44.

I have begin testing to see how fast the file can be read in a few
different scenarios:

while(  ) {
}

It only takes about 6 seconds to read 4,112,220 lines.

But when I introduce split as such:

while () {
chomp($_);
my @tokens = split( ;, $_ );
}

It takes around 7 minutes to reach eof.

I also tried using a LIMIT on split as shown below:
It helped greatly by only taking a little over 1 minute but I am curious if
there is a way to still improve the time to read in the file or is this a
reasonable time.

while () {
chomp($_);
my @tokens = split( ;, $_, 44 );
}

Thank you,

Chris


printf

2013-03-04 Thread Chris Stinemetz
I would like to pass a list of variables to printf.

Is there a way to multiply a set printf length instead of
righting typing printf for each variable?

what I am trying to do is below:

 printf %-${longest}s x 27\n,

 
$rptType,$mkt,$timeStamp,$cell,$sector,$carr,$satt,$sest,$fit,$psEst,$catt,$cest,$pcEst,$rfLost,

 
$cpDropCell,$cpDropRnc,$tuneAway,$tDrops,$pDcr,$ia,$pIa,$tccf,$failAp,$failTp,$failA10,$failAAA,$failPDSN;

Thank you,

Chris


Re: separating code in two files

2013-03-02 Thread Chris Stinemetz
On Fri, Mar 1, 2013 at 3:37 PM, Chris Stinemetz chrisstinem...@gmail.comwrote:



 On Fri, Mar 1, 2013 at 11:00 AM, Shlomi Fish shlo...@shlomifish.orgwrote:

 Hi Jim,

 On Thu, 28 Feb 2013 11:21:59 -0800
 Jim Gibson jimsgib...@gmail.com wrote:

 
  On Feb 28, 2013, at 10:31 AM, Chris Stinemetz wrote:
 
   I want to put a hash declaration in a separate file from the main
 script.
   How do I do this correctly?
  
   perl.pl ( main script )
  
   #!/usr/bin/perl
   use warnings;
   use strict;
   use Data::Dumper;
  
   require lib.pl;
  
   print Dumper \%hash;
  
   lib.pl ( library script )
  
   #!/usr/bin/perl
   use warnings;
   use strict;
  
   my %hash = (
 Version = 0,
 SRT = 11,
 SRFC = 12,
 CFC = 21,
 CFCQ = 22,
 ICell = 29,
 ISector = 30,
 Cell = 31,
 Sector = 32,
   );
  
   1;
  
   The error I am getting:
  
   Global symbol %hash requires explicit package name at perl.pl line
 8.
   Execution of perl.pl aborted due to compilation errors.
 
  Put the following line in the main script:
 
  our %hash;
 
  Change the my %hash = ( ... ); declaration in lib.pl to our %hash =
  (...);.
 
  In your original versions, %hash was a lexical variable in lib.pl, and
 thus
  not in scope within perl.pl. Using 'our' instead of 'my' makes %hash a
  package variable (in package main::), and as such is accessible by both
  perl.pl and lib.pl, The 'our' declaration also lets you leave off the
 package
  name when you access the variable.
 

 It is a better idea to put this inside a module and export a subroutine
 for
 accessing it (or use an object-oriented interface). See:

 http://perl-begin.org/topics/modules-and-packages/

 Untested code:

 
 ## This is the file MyModule.pm - don't call it that.
 package MyModule;

 use parent 'Exporter';

 our @EXPORT = (qw(get_ref_to_global_hash));

 my %global_hash = (
 'donald' = 'duck',
 'mickey' = 'mouse',
 'goofy' = 'dog',
 );

 sub get_ref_to_global_hash
 {
 return \%global_hash;
 }

 # Module should return a true value.
 1;
 

 Regards,

 Shlomi Fish


With Shlomi's approach how would I access each element in the %global_hash
within the main script calling the function?

Below is what I have attempted.

**Containers.pm**

## This is the file Containers.pm
package Containers;

use parent 'Exporter';

our @EXPORT = (qw(get_global_hash));

my %global_hash = (
'donald' = 'duck',
'mickey' = 'mouse',
'goofy' = 'dog',
);


sub get_global_hash
{
return \%global_hash;
}

1;

**try.pl**

#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;

use Containers;

print Hello, \n;

# our %global_hash;

print get_global_hash;

# print Dumper \%global_hash;


nested subroutines

2013-03-02 Thread Chris Stinemetz
Thanks in advance.

I have a subroutine inside another subroutine in a module I am tyring to
put together.

I would like to pass the value assigned to $srt in the while loop as the
parameter for the session_attempts subroutine called withing the
processPegs subroutine.

The error I am getting is:

Use of uninitialized value $_srt in numeric ne (!=) at ...

For example:

main program:

while()
{
   chomp($_);
   next if $_ =~ /PACE/;
   my @tokens = split(;,$_);

   $srt = $tokens[$fieldMap{SRT}];
   processPegs($c_s,\%evdo);
}

module:

sub processPegs {
   my($_cs, $_t) = @_;

   $_t-{$_cs}{$pegs[0]} += session_attempts($srt);
}

Chris


Re: nested subroutines

2013-03-02 Thread Chris Stinemetz


Sent from my iPhone

On Mar 2, 2013, at 7:49 PM, John W. Krahn jwkr...@shaw.ca wrote:

 Chris Stinemetz wrote:
 Thanks in advance.
 
 I have a subroutine inside another subroutine in a module I am tyring to
 put together.
 
 I would like to pass the value assigned to $srt in the while loop as the
 parameter for the session_attempts subroutine called withing the
 processPegs subroutine.
 
 The error I am getting is:
 
 Use of uninitialized value $_srt in numeric ne (!=) at ...
 
 The code provided does not use the ne operator nor does it use the variable 
 $_srt
 
 
 
 John
 -- 
 Any intelligent fool can make things bigger and
 more complex... It takes a touch of genius -
 and a lot of courage to move in the opposite
 direction.   -- Albert Einstein
 
 -- 
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/
 
 

Correct. I was able to figure it out.

Thanks,

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




Re: separating code in two files

2013-03-01 Thread Chris Stinemetz
On Fri, Mar 1, 2013 at 11:00 AM, Shlomi Fish shlo...@shlomifish.org wrote:

 Hi Jim,

 On Thu, 28 Feb 2013 11:21:59 -0800
 Jim Gibson jimsgib...@gmail.com wrote:

 
  On Feb 28, 2013, at 10:31 AM, Chris Stinemetz wrote:
 
   I want to put a hash declaration in a separate file from the main
 script.
   How do I do this correctly?
  
   perl.pl ( main script )
  
   #!/usr/bin/perl
   use warnings;
   use strict;
   use Data::Dumper;
  
   require lib.pl;
  
   print Dumper \%hash;
  
   lib.pl ( library script )
  
   #!/usr/bin/perl
   use warnings;
   use strict;
  
   my %hash = (
 Version = 0,
 SRT = 11,
 SRFC = 12,
 CFC = 21,
 CFCQ = 22,
 ICell = 29,
 ISector = 30,
 Cell = 31,
 Sector = 32,
   );
  
   1;
  
   The error I am getting:
  
   Global symbol %hash requires explicit package name at perl.pl line
 8.
   Execution of perl.pl aborted due to compilation errors.
 
  Put the following line in the main script:
 
  our %hash;
 
  Change the my %hash = ( ... ); declaration in lib.pl to our %hash =
  (...);.
 
  In your original versions, %hash was a lexical variable in lib.pl, and
 thus
  not in scope within perl.pl. Using 'our' instead of 'my' makes %hash a
  package variable (in package main::), and as such is accessible by both
  perl.pl and lib.pl, The 'our' declaration also lets you leave off the
 package
  name when you access the variable.
 

 It is a better idea to put this inside a module and export a subroutine for
 accessing it (or use an object-oriented interface). See:

 http://perl-begin.org/topics/modules-and-packages/

 Untested code:

 
 ## This is the file MyModule.pm - don't call it that.
 package MyModule;

 use parent 'Exporter';

 our @EXPORT = (qw(get_ref_to_global_hash));

 my %global_hash = (
 'donald' = 'duck',
 'mickey' = 'mouse',
 'goofy' = 'dog',
 );

 sub get_ref_to_global_hash
 {
 return \%global_hash;
 }

 # Module should return a true value.
 1;
 

 Regards,

 Shlomi Fish

 --
 -
 Shlomi Fish   http://www.shlomifish.org/
 Interview with Ben Collins-Sussman - http://shlom.in/sussman

 Sometimes you don’t need to be familiar with a better alternative to know
 that
 something sucks. Take Microsoft Word for example.
 — Shlomi Fish’s friend.

 Please reply to list if it's a mailing list post - http://shlom.in/reply .

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


 How would I then access the hash in the main script?

Thank you,

Chris


separating code in two files

2013-02-28 Thread Chris Stinemetz
I want to put a hash declaration in a separate file from the main script.
How do I do this correctly?

perl.pl ( main script )

#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;

require lib.pl;

print Dumper \%hash;

lib.pl ( library script )

#!/usr/bin/perl
use warnings;
use strict;

my %hash = (
   Version = 0,
   SRT = 11,
   SRFC = 12,
   CFC = 21,
   CFCQ = 22,
   ICell = 29,
   ISector = 30,
   Cell = 31,
   Sector = 32,
);

1;

The error I am getting:

Global symbol %hash requires explicit package name at perl.pl line 8.
Execution of perl.pl aborted due to compilation errors.


Re: separating code in two files

2013-02-28 Thread Chris Stinemetz



 Put the following line in the main script:

 our %hash;

 Change the my %hash = ( ... ); declaration in lib.pl to our %hash =
 (...);.

 In your original versions, %hash was a lexical variable in lib.pl, and
 thus not in scope within perl.pl. Using 'our' instead of 'my' makes %hash
 a package variable (in package main::), and as such is accessible by both
 perl.pl and lib.pl, The 'our' declaration also lets you leave off the
 package name when you access the variable.




Thank you very much! That did the trick.

Chris


Re: matching certain lines

2013-02-10 Thread Chris Stinemetz
Thank you everyone for you help.

-Chris


On Sat, Feb 9, 2013 at 5:15 PM, Uri Guttman u...@stemsystems.com wrote:

 On 02/09/2013 03:59 PM, John W. Krahn wrote:


 Let's re-factor that down to its essence:

 while ( DATA ) {
  print if /\|68\|/;
  print $1\t$2\t$3\n if /(\|\d)\|(\d+)\|(\d+)/;
  }

 Now we need to add something that starts at |68| and stops at #END:

 while ( DATA ) {
  if ( /\|68\|/ .. /^#END/ ) {
  print if /\|68\|/;
  print $1\t$2\t$3\n if /(\|\d)\|(\d+)\|(\d+)/;
  }
  }


 there is a great feature with the .. flip/flop op that isn't well known.
 it returns not just a boolean state but a count of where it is in the
 range. so you can use that value to handle the first line differently and
 not need to copy the regex which can lead to a bug if it changes and you
 forget to edit both copies:

 if ( my $range = /\|68\|/ .. /^#END/ ) {
 print if $range == 1 ;

 the last line in the range gets a number with E0 appended so it is the
 same value but you can check for the /E/ and do something there:

 print DONE\n if $range =~ /E/ ;

 uri




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





Re: matching certain lines

2013-02-10 Thread Chris Stinemetz
To take this a step further.

How would you go about creating a hash to sum up all the values in group $3
utilizing the flip/flop operator and print the results of the key and value
with the key being group $2?

Thank you,

Chris

while( DATA ) {
if ( /0x3\|68\|/ .. /^#END/ ) {
print if /\|68\|/;
print join(,, $1, $2, $3 ), \n if /\|(\d)\|(\d+)\|(\d+)/;
}
}

__DATA__
#LOGNUM|110|OPERATIONAL
|NETWORK.1:SUBNETWORK.100:EBSC.1:EBSCSHELF.4:DSFPVCARD.5
|6261.2.0.330.1.1|6261.2.0.330.1.1|0x3|68|1|1
|ACP2|12
|7|1|0
|7|2|2636
|7|3|0
|7|4|0
|7|5|2601
|7|6|0
|7|7|0
|7|8|0
|7|9|0
|7|10|0
|7|11|0
|7|12|0
#END


#LOGNUM|134|OPERATIONAL
|NETWORK.1:SUBNETWORK.100:EBSC.1:EBSCSHELF.4:DSFPVCARD.5
|6261.2.0.330.1.1|6261.2.0.330.1.1|0x3|68|1|1
|ACP5|12
|7|1|0
|7|2|2638
|7|3|0
|7|4|0
|7|5|2592
|7|6|0
|7|7|0
|7|8|0
|7|9|0
|7|10|0
|7|11|0
|7|12|0
#END


#LOGNUM|150|OPERATIONAL
|NETWORK.1:SUBNETWORK.100:EBSC.1:EBSCSHELF.4:DSFPVCARD.7
|6263.2.0.330.1.1|6263.2.0.330.1.1|0x3|68|1|1
|ACP1|12
|7|1|0
|7|2|2573
|7|3|0
|7|4|0
|7|5|2551
|7|6|0
|7|7|0
|7|8|0
|7|9|0
|7|10|0
|7|11|0
|7|12|0
#END


Re: matching certain lines

2013-02-10 Thread Chris Stinemetz
On Sun, Feb 10, 2013 at 8:05 AM, Chris Stinemetz
chrisstinem...@gmail.comwrote:

 To take this a step further.

 How would you go about creating a hash to sum up all the values in group
 $3 utilizing the flip/flop operator and print the results of the key and
 value with the key being group $2?


This is what I came up with and seems to do the trick. Hopefully it can
help someone else.

my %hash;
while (DATA) {
if ( /0x3\|68\|/ .. /^#END/ ) {
if (/\|(\d)\|(\d+)\|(\d+)/) {
my @cols = ( $1, $2, $3 );
$hash{ $cols[1] }{instance}++;
$hash{ $cols[1] }{volume} += $cols[2];
}
}
}


## header
print join(,, qw( Peg Instance Subtotal )), \n;

foreach ( sort { $a = $b } keys(%hash) ) {
print join( ,, $_, $hash{$_}{instance}, $hash{$_}{volume} ), \n;
}


matching certain lines

2013-02-09 Thread Chris Stinemetz
I would like to only work with the data that has a line with |68| in it
print that line and then print each subsequent lines in that match
/\|7\|\d+\|\d+/ until #END is reached and then repeat for the rest of the
input data.

Below is what I have attempted.

Thanks in advance.

Chris


#!/usr/bin/perl

use warnings;
use strict;

my ( $col1, $col2, $col3 );

while( my $line = DATA ) {
chomp($line);
if ( $line =~ /(.*\|68\|.*)/ ) {
my $OM = $1;
print $OM, \n;
}
 if ( $line =~ /(\|\d)\|(\d+)\|(\d+)/ ) {
$col1 = $1;
$col2 = $2;
$col3 = $3;
print join(\t, $col1, $col2, $col3 ), \n;
}
}


__DATA__
#LOGNUM|68|OPERATIONAL
|NETWORK.1:SUBNETWORK.100:EBSC.1:EBSCSHELF.3:DSFPVCARD.6
|5883.2.0.330.1.1|5883.2.0.330.1.1|0x3|19|1|1
|ACP3|8
|7|1|9
|7|2|436
|7|3|5
|7|4|0
|7|5|0
|7|6|0
|7|7|0
|7|8|0
#END


#LOGNUM|69|OPERATIONAL
|NETWORK.1:SUBNETWORK.100:EBSC.1:EBSCSHELF.3:DSFPVCARD.6
|5883.2.0.330.1.1|5883.2.0.330.1.1|0x3|26|1|1
|ACP3|19
|7|1|0
|7|2|0
|7|3|0
|7|4|0
|7|5|0
|7|6|0
|7|7|0
|7|8|0
|7|9|0
|7|10|20
|7|11|0
|7|12|0
|7|13|0
|7|14|0
|7|15|0
|7|16|0
|7|17|0
|7|18|0
|7|19|0
#END


#LOGNUM|70|OPERATIONAL
|NETWORK.1:SUBNETWORK.100:EBSC.1:EBSCSHELF.3:DSFPVCARD.6
|5883.2.0.330.1.1|5883.2.0.330.1.1|0x3|68|1|1
|ACP3|12
|7|1|0
|7|2|2610
|7|3|0
|7|4|0
|7|5|2575
|7|6|0
|7|7|0
|7|8|0
|7|9|0
|7|10|0
|7|11|0
|7|12|0
#END


Re: delete blank lines from text file

2012-10-01 Thread Chris Stinemetz
On Mon, Oct 1, 2012 at 3:34 AM, Irfan Sayed irfan_sayed2...@yahoo.com wrote:
 hi,

 i need to delete all blank lines from the text file



I usually just skip the blank lines when I read the data one line at a
time. Then you can print to a new file.
My example is below:

#!/usr/bin/perl

use 5.010;
use strict;
use warnings;

while ( my $line = DATA ) {
next if $line =~ /^$/;
print $line;
}
print \n;

__DATA__
line 1

line 3
line 4

line 6

line 8

**OUTPUT**
line 1
line 3
line 4
line 6
line 8

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




milliseconds converted to timestamp

2012-09-27 Thread Chris Stinemetz
Hello List,

I have the following millisecond value: 54599684
This represents a timestamp reported as milliseconds past midnight local time.

Is there a module to convert this into a hh::mm format? Or a Perlish
example to handle this?

Thank you,

Chris

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




Re: milliseconds converted to timestamp

2012-09-27 Thread Chris Stinemetz
On Thu, Sep 27, 2012 at 10:46 AM, Jim Gibson jimsgib...@gmail.com wrote:

 On Sep 27, 2012, at 8:16 AM, Chris Stinemetz wrote:

 Hello List,

 I have the following millisecond value: 54599684
 This represents a timestamp reported as milliseconds past midnight local 
 time.

 Is there a module to convert this into a hh::mm format? Or a Perlish
 example to handle this?

 my $t=54599684;
 printf(%02d:%02d\n, ($t/360),(($t/6)%60));

 15:09


Your example works perfectly.

Thank you so much,

Chris

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




Re: cgi development environment

2012-09-19 Thread Chris Stinemetz
I have my Perl cgi development environment all set-up. I actually
wound up setting up an instance through Amazon AWS.
Very cool service by Amazon.

I am having issues with my first script and have hopes someone may be
able to explain to me whey it isn't working correctly.

The error is coming form line 11 and the error is:

Premature end of script headers: test2.cgi
Bareword left not allowed while strict subs in use at
/usr/lib/cgi-bin/test2.cgi line 7.
Execution of /usr/lib/cgi-bin/test2.cgi aborted due to compilation errors.
Premature end of script headers: test2.cgi


  1 #!/usr/bin/perl
  2 use warnings;
  3 use strict;
  4 use CGI;
  5
  6 my $q = CGI-new;
  7 print $q-header(-type='text/html'),
  8   $q-start_html('hello world'), # start the HTML
  9   $q-h1({-align=right},'hello world'), # level 1 header
 10   $q-h1({-align=left});
 11   $q-h1('some','contents');
 12   $q-end_html;  # end the HTML

Thank you in advance,

-Chris

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




Re: cgi development environment

2012-09-19 Thread Chris Stinemetz

 You have a couple other issues.  Since you have one print statement, spread
 over multiple lines, the semi-colons on lines 10 and 11 are bugs.  They
 should be commas.  The semi-colons terminate the statement resulting in
 syntax errors.

 Mike

Thank you. That fixed it.

-Chris

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




cgi development environment

2012-09-18 Thread Chris Stinemetz
Hello list,

I am very interested in cgi scripting. I have only used php for web
development in the past.
Would someone please let me know of any good tutorials to get windows
based web development environment set up and get my feet wet?

Thank you in advance,

Chris

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




Re: cgi development environment

2012-09-18 Thread Chris Stinemetz
On Tue, Sep 18, 2012 at 5:46 AM, Mark Haney ma...@abemblem.com wrote:
 On 09/18/2012 08:34 AM, Chris Stinemetz wrote:

 Hello list,

 I am very interested in cgi scripting. I have only used php for web
 development in the past.
 Would someone please let me know of any good tutorials to get windows
 based web development environment set up and get my feet wet?

 Thank you in advance,

 Chris


 Is there any particular reason it has to be Windows based?  Not that I think
 it matters, but perl works okay on windows, but it's not a platform combo I
 would recommend.

 Would you consider learning it in a VM in Linux?

 Otherwise I can get you setup in windows with Perl if you like.  I had to
 write up a setup sheet when I was working on a project.


I'm not against using VM to set-up a linux box. If you have a write up
I would like to see it.

Thank you,

Chris

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




Re: how to deal with columns in perl

2012-09-17 Thread Chris Stinemetz
On Mon, Sep 17, 2012 at 1:29 PM, Wang, Li li.w...@ttu.edu wrote:
 Dear List members

 I have three columns of a table.  The example is as follows:

 DBS R^2 genename
 801 0.27807486057281494 POPTR_0002s00200
 19031.0 POPTR_0002s00200
 11030.25852271914482117 POPTR_0002s00200
 32150.03134157508611679 POPTR_0002s00200
 24150.010018552653491497POPTR_0002s00200
 13130.03134157508611679 POPTR_0002s00200
 34421.0 POPTR_0002s00200
 26420.25852271914482117 POPTR_0002s00200
 15401.0 POPTR_0002s00200
 228 0.03134157508611679 POPTR_0002s00200
 30990.026160990819334984POPTR_0002s00210
 75550.80011920929   POPTR_0002s00210
 44570.014814814552664757POPTR_0002s00210
 75645.232862313278019E-4POPTR_0002s00210
 44660.0018315018387511373   POPTR_0002s00210
 10  0.0036630036775022745   POPTR_0002s00210
 75655.232862313278019E-4POPTR_0002s00210
 44670.0018315018387511373   POPTR_0002s00210
 11  0.0036630036775022745   POPTR_0002s00210
 2   1.0 POPTR_0002s00210

 I would like to calculate the average value of column 2 while the content of 
 column three is the same. In this case, I would like the output of my result 
 be as follows:
 R^2 genename
 0.3899163577POPTR_0002s00200
 0.2314956035POPTR_0002s00210


Maybe something like this:

HTH,

Chris

#!/usr/bin/perl

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

my %hash;
my $counter;

while ( my $line = DATA ) {

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

## check to see if we've already added the 3rd column to the hash
## if we have, start counting how many times is shows up
## else add it to the hash with the values of @record[ 0 .. 2 ] and
## counter starting at 1 since first occurence
if ( defined $hash{ $record[2]} ) {
$counter++;
my @trec = @{ $hash{$record[2]} };

$hash{$record[2]} = [
$trec[0], $trec[1] + $record[1],
$trec[2], $counter
];
}

else {
$hash{ $record[2] } = [ @record[ 0 .. 2 ] ];
$counter = 1;
}
}
print Dumper \%hash;


__DATA__
DBS R^2 genename
801 0.27807486057281494 POPTR_0002s00200
19031.0 POPTR_0002s00200
11030.25852271914482117 POPTR_0002s00200
32150.03134157508611679 POPTR_0002s00200
24150.010018552653491497POPTR_0002s00200
13130.03134157508611679 POPTR_0002s00200
34421.0 POPTR_0002s00200
26420.25852271914482117 POPTR_0002s00200
15401.0 POPTR_0002s00200
228 0.03134157508611679 POPTR_0002s00200
30990.026160990819334984POPTR_0002s00210
75550.80011920929   POPTR_0002s00210
44570.014814814552664757POPTR_0002s00210
75645.232862313278019E-4POPTR_0002s00210
44660.0018315018387511373   POPTR_0002s00210
10  0.0036630036775022745   POPTR_0002s00210
75655.232862313278019E-4POPTR_0002s00210
44670.0018315018387511373   POPTR_0002s00210
11  0.0036630036775022745   POPTR_0002s00210
2   1.0 POPTR_0002s00210

__END___
## Output ##
$VAR1 = {
  'genename' = [
  'DBS',
  'R^2',
  'genename'
],
  'POPTR_0002s00200' = [
  '801',
  '3.8991635767743',
  'POPTR_0002s00200',
  10
],
  'POPTR_0002s00210' = [
  '3099',
  '1.85301140078809',
  'POPTR_0002s00210',
  10
]
};

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




Re: how to deal with columns in perl

2012-09-17 Thread Chris Stinemetz
Sorry forgot you wanted the average.
Revised program is below:

#!/usr/bin/perl

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

my %hash;
my $counter;

while ( my $line = DATA ) {

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

## check to see if we've already added the 3rd column to the hash
## if we have, start counting how many times is shows up
## else add it to the hash with the values of @record[ 0 .. 2 ] and
## counter starting at 1 since first occurence
if ( defined $hash{ $record[2]} ) {
$counter++;
my @trec = @{ $hash{$record[2]} };

$hash{$record[2]} = [
$trec[0], $trec[1] + $record[1],
$trec[2], $counter, avg( $trec[1], $record[1], $counter )
];


}

else {
$hash{ $record[2] } = [ @record[ 0 .. 2 ] ];
$counter = 1;


}
}
print Dumper \%hash;


sub avg {
my ( $x, $y, $total ) = @_;
return ($x + $y) / $total;
}

__DATA__
DBS R^2 genename
801 0.27807486057281494 POPTR_0002s00200
19031.0 POPTR_0002s00200
11030.25852271914482117 POPTR_0002s00200
32150.03134157508611679 POPTR_0002s00200
24150.010018552653491497POPTR_0002s00200
13130.03134157508611679 POPTR_0002s00200
34421.0 POPTR_0002s00200
26420.25852271914482117 POPTR_0002s00200
15401.0 POPTR_0002s00200
228 0.03134157508611679 POPTR_0002s00200
30990.026160990819334984POPTR_0002s00210
75550.80011920929   POPTR_0002s00210
44570.014814814552664757POPTR_0002s00210
75645.232862313278019E-4POPTR_0002s00210
44660.0018315018387511373   POPTR_0002s00210
10  0.0036630036775022745   POPTR_0002s00210
75655.232862313278019E-4POPTR_0002s00210
44670.0018315018387511373   POPTR_0002s00210
11  0.0036630036775022745   POPTR_0002s00210
2   1.0 POPTR_0002s00210
__END__

##Dumper Output##

$VAR1 = {
  'genename' = [
  'DBS',
  'R^2',
  'genename'
],
  'POPTR_0002s00200' = [
  '801',
  '3.8991635767743',
  'POPTR_0002s00200',
  10,
  '0.38991635767743'
],
  'POPTR_0002s00210' = [
  '3099',
  '1.85301140078809',
  'POPTR_0002s00210',
  10,
  '0.185301140078809'
]
};

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




Re: socket port

2012-09-02 Thread Chris Stinemetz
Thank you Peng. Are there any other suggestions from the list?

Thanks in advance,

Chris


Re: socket port

2012-09-02 Thread Chris Stinemetz
Thank you so much Jim.

-Chris


Re: greater circle

2012-08-30 Thread Chris Stinemetz


 Because floating-point arithmetic as done by limited precision computers is 
 always an approximation. An IEEE 754 double-precision 64-bit floating point 
 number uses a 53-bit fraction and therefore has about 16 decimal digits of 
 precision. So calculating zero within 13 digits (e-013) is pretty good.

 The calculation done by the Geo::Ellipsoid module is very complex and 
 involves sines, cosines, tangents, etc. Precision will be lost with each 
 floating-point operation.

 Have you worked out what 2e-13 miles is in inches? For all practical 
 purposes, it IS zero.


Thank you for the great explanation. Yes that is close enough to 0 for
me :) Thanks again.

-Chris

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




socket port

2012-08-30 Thread Chris Stinemetz
Hello List,

I am creating a program, where for the first time, I will be reading
in data from a socket port.

I am a bit confused about how to print the processed data while still
reading in data from the port. Thus far, I have only processed data
from a file where the while loop ends  when EOF criteria has been met.

So my question is how do I continue to read in data from the port and
print the generated array as it is being created?

snippet:

#!/usr/bin/perl

use strict;
use warnings;
use IO::Socket;
use Data::Dumper;


my $host = 'ip..address';
my $port = portnum;
my $sock = new IO::Socket::INET(
PeerAddr = $host,
PeerPort = $port,
Proto= 'tcp'
);

die cannot open socket $! unless ($sock);

my @array;
while ( my $line = $sock ) {

  do stuff and create array...

  push @array, [  stuff  ];

}
## print @array
for my $item (@array) {
print join(,,@$item),\n;
}

Thanks in advance,

Chris

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




greater circle

2012-08-29 Thread Chris Stinemetz
Hello List,

I'm tyring to find the distance in miles between two sets of
coordinates by using the module Math::Trig

I'm expecting the return distance to be around 16.91 miles.

Any help is greatly appriciated.

Chris

#!/usr/bin/perl

use strict;
use warnings;
use Math::Trig qw(pi great_circle_distance);

my $LAT1 = 39.316858;
my $LAT2 = 39.243556;
my $LONG1 = -94.963194;
my $LONG2 = -94.6617;
print great_circle_distance($LONG1, pi/2 - $LAT1, $LONG2, pi/2 - $LAT2);

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




Re: greater circle

2012-08-29 Thread Chris Stinemetz

 The Math::Trig routines all work with radians. Therefore, you are going to 
 have to convert your locations from degrees to radians. You can use the 
 Math::Trig::deg2rad function. Note that pi/2 is radians, so you are 
 subtracting degrees from radians, which never works.

 The great_circle_distance function returns radians by default, so you are 
 going to have to convert the return values into miles using the approximate 
 radius of the earth in miles (~3963mi). Note that the earth is not a perfect 
 sphere, so it doesn't have just one radius, but varies from pole to equator.

 If you want to do latitude, longitude, and distance calculations, there are 
 modules available from CPAN. I can mention Geo::Distance, GIS::Distance, and 
 Geo::Ellipsoid (which I wrote). These modules take into account the fact that 
 the earth not perfectly spherical.

 Here is your program modified to compare results from Geo::Ellipsoid and 
 Math::Trig::great_circle_distance.

 #!/usr/bin/perl

 use strict;
 use warnings;
 use feature qw(say);
 use Math::Trig qw(pi great_circle_distance deg2rad);
 use Geo::Ellipsoid;

 my $earth_meters = 6378137.0;
 my $meters_per_mile = 1609.34;
 my $earth_miles = $earth_meters / $meters_per_mile;
 say The radius of the earth is $earth_miles miles;

 my $lat1 = 39.316858;
 my $lat2 = 39.243556;
 my $lon1 = -94.963194;
 my $lon2 = -94.6617;

 my $latrad1 = deg2rad($lat1);
 my $latrad2 = deg2rad($lat2);
 my $lonrad1 = deg2rad($lon1);
 my $lonrad2 = deg2rad($lon2);

 my $dist = great_circle_distance($lonrad1, pi/2 - $latrad1, $lonrad2, pi/2 - 
 $latrad2);
 say $dist * $earth_meters / $meters_per_mile;

 my $ellipsoid = Geo::Ellipsoid-new(units='degrees', dist='miles');
 say $ellipsoid-range($lat1,$lon1,$lat2,$lon2);


 Results:

 The radius of the earth is 3963.20044241739 miles
 16.9202528447011
 16.9368500188459


Thank you Jim. Your module seems to be the solution I am looking for.
Just one question. If the two sets of coordinates are the same I was
expecting the distance to be 0 miles.

Instead I get:

2.19558883102012e-013

For the following example.

#!/usr/bin/perl

use strict;
use warnings;

use feature qw(say);
use Geo::Ellipsoid;

my $lat1 = 39.316858;
my $lat2 = 39.316858;
my $lon1 = -94.963194;
my $lon2 = -94.963194;


my $ellipsoid = Geo::Ellipsoid-new(units='degrees', dist='miles');
say $ellipsoid-range($lat1,$lon1,$lat2,$lon2);

If it is the expected outcome would you please explain why?

Thank you,

Chris

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




array element access

2012-08-27 Thread Chris Stinemetz
Hello list,

Is this not possible?

I am trying to incorporate sprintf to access an element in an array.

Is this not possible or am i doing something wrong?

$cp_cell = sprintf($data[%s], $cp_cell_index);

The error:

Global symbol %s requires explicit package name at form.pl line 167.
Execution of form.pl aborted due to compilation errors.
Press any key to continue . . .


Thank you in advance,

Chris

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




grep array of arrays

2012-08-23 Thread Chris Stinemetz
Hello List,
I'm trying to grep an array of arrays, but I am getting the following error:

Can't use string (1) as an ARRAY ref while strict refs in use at
form.pl line 121, $COORDS line 1281.
Press any key to continue . . .



Below is the grep statement:

print grep { $_-[0][0] = 0 } @coords;
Any idea what I am doing wrong?

Thank in advance,

Chris

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




Re: grep array of arrays

2012-08-23 Thread Chris Stinemetz


 If @coords is just an Array of Arrays then that should be:

 print grep { $_-[0] = 0 } @coords;


 Your example thinks @coords is an Array of Arrays of Arrays.


 John
 --


print grep { $_-[0] = 0 } @coords;

Just prints the memory adress:
ARRAY(0x29d459c)ARRAY(0x29d462c)ARRAY(0x29d46cc)

apparently I am not dereferencing the data structure correctly.

Below is a sample of what it looks like.

$VAR1 = [
  [
1,
1,
'70',
'90',
undef
  ],
  [
1,
2,
'200',
'65',
undef
  ],

Thanks for you time,

Chris

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




hash of arrays sorting

2012-08-21 Thread Chris Stinemetz
 Hello List,

I am trying to sort a hash of arrays ( example below: )

I would the sort to sort in ascending order the first index of the array
then the second index of the array.

So in this example the arrays would sort to:

97,2,120,65
219,1,30,33
280,3,230,90
462,2,270,65

$VAR1 = {
  '462-2' = [
   '462',
   '2',
   '270',
   '65'
 ],
  '219-1' = [
   '219',
   '1',
   '30',
   '33'
 ],
  '280-3' = [
   '280',
   '3',
   '230',
   '90'
 ],
  '97-2' = [
  '97',
  '2',
  '120',
  '65'

};

Thanks in advance,

Chris


Re: hash of arrays sorting

2012-08-21 Thread Chris Stinemetz
On Tue, Aug 21, 2012 at 3:11 PM, Shawn H Corey shawnhco...@gmail.comwrote:

 On Tue, 21 Aug 2012 15:05:33 -0500
 Chris Stinemetz chrisstinem...@gmail.com wrote:

  I am trying to sort a hash of arrays ( example below: )
 
  I would the sort to sort in ascending order the first index of the
  array then the second index of the array.

 What have you tried so far? Can we see the code?

 Yes you may.
This is what I have tried so far:

foreach my $cellNo ( keys %hash ) {
print join( \0, sort {$a=$b} @{ $hash{$cellNo} } ),\n;
}

Thank you in advance,

chris


Re: hash of arrays sorting

2012-08-21 Thread Chris Stinemetz
 I will leave it to you to write an actual program incorporating these
 ideas.

 Thank you Jim for the excelent explanation.

This seems to do the trick.

foreach my $cellNo ( sort { $hash{$a}-[0] = $hash{$b}-[0] ||
$hash{$a}-[1] = $hash{$b}-[1]  } keys %hash ) {
print join( \0, @{ $hash{$cellNo} } ),\n;
}

-Chris


awk to Perl

2012-08-20 Thread Chris Stinemetz
Hello List,

I'm tyring to covert an AWK script to Perl. Is there a better alternative
then a2p?

http://perldoc.perl.org/a2p.html

Thanks in advance,

Chris


array question

2012-08-19 Thread Chris Stinemetz
Hello List,

I have input data such as far below:

I would like to read the data into an array and modify the 2nd index if the
0th and first indices are identical.
I would like the updated 2nd index to be an average of the 2nd index where
both occurences of 0th and 1st indices match.

So for example below:

The records that contain 24 1 I would like to average the second index 60
and 40

and print the new value like this:

... # print input data
24 1 50 65
24 1 50 65
... # print rest of input data




22 1 60 65
22 2 180 90
22 3 300 90
23 1 0 65
23 2 90 65
23 3 260 65
24 1 60 65
24 1 40 65
24 2 180 65
24 2 160 65
24 3 310 65
24 3 290 65
25 1 0 90
25 2 120 65
25 3 240 65
26 1 60 65
26 2 180 65
26 3 320 65
87 1 355 65
87 2 100 65
87 3 245 65
87 3 180 65
88 1 100 65
88 2 210 65
88 3 310 65

Thank you in advance.


subroutine

2012-08-17 Thread Chris Stinemetz
Hello List,
Can this subroutine be better written?
I am getting the following erros:

Use of uninitialized value $y in subtraction (-) at form.pl line 52.
Use of uninitialized value $y in addition (+) at form.pl line 52.

sub avg_az {
  my($x, $y) = shift(@_);
  return abs($x-$y)180 ? ($x+$y)/2 :
  (360+$x+$y)/2360 ? (360+$x+$y)/2 :
  (360+$x+$y)/2-360
}

print avg_az(90,30),\n;

Thank you,

Chris


Re: subroutine

2012-08-17 Thread Chris Stinemetz
 In the above line, `shift` will return just the first element from the
 @_ array. $y will therefore be undefined. The line should be rewritten
 as:
 my ( $x, $y ) = @_;

Thank you. I should have caught that.

Chris


Perl MVC framework

2012-07-19 Thread Chris Stinemetz
Hello List,

What is the best Perl MVC framework for someone to learn that has minimal
web development back ground, but is intermediate with Perl scipting?

I've heard of Catalyst but it seems a bit intimedating.
I just thought I would get some feedback before I choose a framework to
learn.

Thank you in advance,

Chris


array ref as subroutine parameter

2012-07-12 Thread Chris Stinemetz
I have an anonymous array below and would like to know how to pass the
first element to a subroutine as a parameter.

push @data, [$srt,$srfc,$cfc,$cfcq,$cell,$icell,$isector,$sector];

call to subroutine:

session_attempts($srt);

Thank you in advance,

Chris


Re: printing anonymous array

2012-07-08 Thread Chris Stinemetz
Thank you very much.

That was the solution I was looking for.

Take care,

Chris


printing anonymous array

2012-07-07 Thread Chris Stinemetz
Hello list,

I have constructed an anonymous array with all the data I need.
I am having some difficulty in accessing and printing out the data the way
I want.
For the sake of not cluttering this thread too much I have uploaded the
anonymous array Data::Dumper output at github:gist

https://gist.github.com/3066287

The output I am trying to achieve is simply printing out each index 0 for
 each unique occurrence of index 1 (name1-6).

For example: for name 5 in the anonymous array the output should be:

 801  CDM 1, CCU 1, CE 32
812  CDM 1, CCU 1, CE 537
816  CDM 1, 2, CBR 3, 15MHz12
817  CDM 1, 2, CBR 3, 15MHz32
817  CDM 1, 2, CBR 1, 15MHz4
831  CDM 1, 2, CBR 3, 15MHz22
848  CDM 1, CCU 2, CE 18
873  CDM 1, CCU 1, CE 32
874  CDM 3, CCU 1, CE 518
886  ASMB 1 TXAMP 92

Cluster: Name5

_

302  CDM 1, 2, CBR 1, 15MHz2
317  CDM 1, 2, CBR 2, 15MHz17
317  ASMB 1 TXAMP 615
340  TFU 1 4
371  CDM 1, 2, CBR 3, 15MHz1
400  TFU 2 1
517  TFU 1 2
543  TFU 2 2

Cluster: Name6


and print the rest of the instances just like the above.

Sorry if this isn't clear let me know if there are any questions.

Thanks in advance,

Chris


Re: printing anonymous array

2012-07-07 Thread Chris Stinemetz
Thank you very much for your responses.

I have another question.

I would like to replace the second element from hash1 with the second key
from  %hash2

Where both of the firsts keys match in the two hashes. I shortened the
sample data below but there will be a match for each instances of the keys
in the complete data.

Thanks in advance,

Chris

%hash1 = {
  '371' = 2,
  '33' = 2,
  '524' = 14,
  '812' = 54,
  '955' = 5,
  '68' = 2,
  '831' = 34,
};


%hash2 = {
  '105' = {
 'Name1' = 1
   },
  '473' = {
 'Name6' = 1
   },
  '925' = {
 'Name5' = 1
   },
  '840' = {
 'Name4' = 1
   },
  '3' = {
   'Name1' = 1
 },
  '390' = {
 'Name6' = 1
   },
  '146' = {
 'Name1' = 1
   },
  '111' = {
 'Name2' = 1
   },
  '38' = {
'Name2' = 1
  },
  '356' = {
 'Name6' = 1
   },
  '802' = {
 'Name4' = 1
   },
  '4' = {
   'Name1' = 1
 },
  '528' = {
 'Name6' = 1
   },
  '164' = {
 'Name2' = 1
   },
  '196' = {
 'Name1' = 1
   },
  '807' = {
 'Name4' = 1
   },
  '945' = {
 'Name5' = 1
   }
};


Re: hash sort on value

2012-07-03 Thread Chris Stinemetz
On Tue, Jul 3, 2012 at 5:11 AM, xiyoulaoyuanjia
xiyoulaoyuan...@gmail.com wrote:
 hi Rob 。 i do not know  what the 'for' meaning inprint $_-[0], \n for
 sort { $b-[1] = $a-[1] } @RNC;
 can you give me mush information about this use 。
 3ks !


I believe xiyoulaoyuan...@gmail.com intended to send this question to the list.

-Chris

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




Re: hash sort on value

2012-07-03 Thread Chris Stinemetz
On Tue, Jul 3, 2012 at 6:44 AM, Chris Stinemetz
chrisstinem...@gmail.com wrote:
 On Tue, Jul 3, 2012 at 5:11 AM, xiyoulaoyuanjia
 xiyoulaoyuan...@gmail.com wrote:
 hi Rob 。 i do not know  what the 'for' meaning inprint $_-[0], \n for
 sort { $b-[1] = $a-[1] } @RNC;
 can you give me mush information about this use 。
 3ks !


 I believe xiyoulaoyuan...@gmail.com intended to send this question to the 
 list.

I will take a stab at explaining it.

The for is just a loop construct that is using the 2nd sorted
element of the anonymous array as a reference point to print each
record (first element in the anonymous array) in the desired order.

-Chris

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




hash sort on value

2012-07-02 Thread Chris Stinemetz
I have a 3 deminsional hash that I would like to sort on the value in
descending order. I can't quite seem to figure it out

The portion of the program I can't get figured out:
## body
foreach my $frameNo ( keys %RNC ) {
  foreach my $ec ( keys %{$RNC{$frameNo}} ) {
my $ec_count = $RNC{$frameNo}{$ec};
  printf $out(%-4s %-25s %-10s\n,$frameNo,$ec,$ec_count);
  }
}


This is what the hash looks like:

$VAR1 = {
  '22' = {
'44021' = '1',
'80002' = '25',
'51002' = '213',
'51009' = '194',
'26005' = '5',
'44003' = '194',
'8' = '50',
'10011' = '156'
  },
  '23' = {
'80002' = '11',
'10013' = '10',
'10014' = '47',
'27006' = '3',
'42065' = '23',
'90001' = '17',
'22008' = '59',
'44003' = '209',
'8' = '54',
'10011' = '155'
  },
  '24' = {
'10012' = '47',
'10013' = '2',
'27001' = '3',
'44003' = '335',
'10011' = '914',
'8' = '21'
  }
};

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




Re: hash sort on value

2012-07-02 Thread Chris Stinemetz

 I believe you want the output lines formatted as they are but sorted in
 descending order of the ec_count value, is that right?

 I suggest that, instead of printing the data straight from the hash you
 store the lines in an array and sort it before displaying the information.

 The code fragment below replaces your own foreach loop and pushes a data
 pair - the output line and its ec_count - onto the array @RNC instead of
 printing it.

 The array is then sorted in order of the ec_counts and the corresponding
 output lines displayed.

 HTH,

 Rob



 foreach my $frameNo ( keys %RNC ) {
   foreach my $ec ( keys %{$RNC{$frameNo}} ) {
 my $ec_count = $RNC{$frameNo}{$ec};
 my $record = sprintf '%-4s %-25s %-10s', $frameNo, $ec, $ec_count;
 push @RNC, [$record, $ec_count];
   }
 }

 print $_-[0], \n for sort { $b-[1] = $a-[1] } @RNC;



Thank you Rob. Your suggestions worked perfectly.

Chris

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




Perl regex

2012-07-01 Thread Chris Stinemetz
I have a two line pattern I would like to match and include 3 groupings.

  59 REPT: EVDO: RNC 24 CP FAILURE SUMMARY SESSION RELEASE
 RAN AUTH FAILURE PPP, ERROR CODE 51001

For final outcome I would like:

$1 = 24
$2 = CP FAILURE SUMMARY SESSION RELEASE RAN AUTH FAILURE PPP
$3 = ERROR CODE 51001


while ( my $line = $FIN ) {
  if ( $line =~ /EVDO:\s*RNC\s*(\d+)(.*\n{1}.*),(ERROR CODE\s*\d+)/m) {
print $line,\n;
  } else {
print No Match\n;
  }
}

I haven't had much luck matching the second line.

Any help is greatly appreciated.

Thanks,

Chris

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




Re: Check parameters for a checkbox

2012-06-15 Thread Chris Stinemetz

 shift_days = [ $q-param('DoW') ]


 And it sorta works.  Now, instead of getting the error message I actually
 get data in that column, but it's like this:

       14 | Second     | 10:23:00  | 10:23:00  | ARRAY(0xa3a6130) |
  3 |


 Where the 'ARRAY' field should have in it 'MTWThF' (for this particular
 row).  I'm passing this to a subroutine that looks like this:

 $dao-insert_shift(\%attrs); #Sub call

 Subroutine:

 sub insert_shift {
      my $self = shift;
      my($attrs) = @_;

      my $m = $self-schema-resultset('Shifts')-new($attrs);
      $m-insert;
 }



 I /think/ the problem lies with the $attrs value.  But I'm not sure what to
 do to fix it.

 Help?

Looks to me like you need to dereference $attrs to get the results you want.

check out:

perldoc perlref

for more information

HTH,

Chris

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




Re: how to print certain field out

2012-06-08 Thread Chris Stinemetz
On Fri, Jun 8, 2012 at 11:44 AM, lina lina.lastn...@gmail.com wrote:
 On Sat, Jun 9, 2012 at 12:16 AM, lina lina.lastn...@gmail.com wrote:
 Hi,

 Here is the to-be-processed file,

 $ more try
  #  RESIDUE AA STRUCTURE BP1 BP2  ACC     N-H--O    O--H-N
 N-H--O    O--H-N    TCO  KAPPA ALPHA  PHI   PSI    X-CA   Y-CA
 Z-CA
    1  174   V              0   0    0      0, 0.0     2,-0.3     0,
 0.0     0, 0.0   0.000 360.0 360.0 360.0 137.8   47.8   27.7   76.9
    2  175   H        -     0   0    0      2,-0.0     2,-0.3     0,
 0.0     0, 0.0  -1.000 360.0-153.6-152.0 146.1   50.8   25.5   78.2

 I wish to print the value under the BP1, namely

 0
 0


Here is how I am able to do it. I'm sure there are better approaches.

HTH,

Chris

#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;

my @data;

while(my $line = DATA ) {
  push @data, [ split /\s+/, $line ];
}

#print Dumper \@data;


for my $item ( @data ) {
  print @$item[4],\n;
}

__DATA__
#  RESIDUE AA STRUCTURE BP1 BP2  ACC N-H--OO--H-NN-H--O
   O--H-NTCO  KAPPA ALPHA  PHI   PSIX-CA   Y-CA   Z-CA
1  174   V  0   00  0, 0.0 2,-0.3 0, 0.0
  0, 0.0   0.000 360.0 360.0 360.0 137.8   47.8   27.7   76.9
2  175   H- 0   00  2,-0.0 2,-0.3 0, 0.0
  0, 0.0  -1.000 360.0-153.6-152.0 146.1   50.8   25.5   78.2


***RESULTS
BP1
0
0

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




return two varibles

2012-06-07 Thread Chris Stinemetz
Not sure what I am doing wrong but my subroutine is only returning the
value on varible. I would like it to return both $end and $start for
the correct parameter I am passing.

Thank you for your help.

#!/usr/bin/perl
use warnings;
use strict;

my %apcHash = (
  M   = { start = 1,
 end   = 299, },
  O   = { start = 900,
 end   = 983, },
  L   = { start = 871,
 end   = 899, },
  I   = { start = 801,
 end   = 850, },
);

sub getMarketCells {
  my $val = shift;
  foreach my $k ( keys %apcHash ) {
my($start, $end) = @{$apcHash{$k}}{qw/start end/};
return($start, $end) if $val eq $k;
  }
  return ;
}

$apc = O;
my $test = getMarketCells($apc);
print $test,\n;

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




Re: return two varibles

2012-06-07 Thread Chris Stinemetz
 You may be returning two values, but you're only catching one.

 Try

 my( $start, $end ) = getMarketCells( $apc );


 chrs,
 john.

You are correct. Thank you very much!

Chris

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




lexical scope

2012-06-05 Thread Chris Stinemetz
Why does this short program only seem to capture the last line of
input in the @array, but when I put the for loop inside the while loop
all lines of input are available in @array.

I thought by declaring the @array outside the while loop would make
all of its contents available once all the lines are read in the while
loop.

Thanks,

Chris

#!/usr/bin/perl
use warnings;
use strict;

my @array;

while ( my $line = DATA ) {
  chomp $line;
  @array = split(/\s+/, $line,-1);
}

for my $item ( @array ) {
  print $item,\n;
}

__DATA__
Line1 c 2 3 4 5 C 7 8 9
Line2 1 2 3 4 5 6 7 8 9
Line3 1 2 3 4 5 D 7 8 9
Line4 1 2 3 4 5 aDC6 7 8 9
Line5 1 2 3 4 5 D 7 8 9
Line6 1 2 3 4 5 dcDC 7 8 9

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




subroutine returning data

2012-06-04 Thread Chris Stinemetz
I have a subroutine that I want to return 1 only if the value of
%{$href-{$_[0]}} is equal to 'ND' for the whole 24 occurences.

Any suggestions is greatly appreciated.

Thank you,

Chris

sub site_offAir {
  for (values %{$href-{$_[0]}}) {
return 1 if $_ eq 'ND'; #need to test all values are eq to 'ND'
  }
  return '';
}


the call tot he sub-routine:
my @ND_wanted = grep site_offAir($_), sort  keys %$href;


an example from the data structure:

$VAR1 = {
  '077' = {
 '00' = 'ND',
 '01' = 'ND',
 '02' = 'ND',
 '10' = 'ND',
 '03' = 'ND',
 '11' = 'ND',
 '20' = 'ND',
 '04' = 'ND',
 '12' = 'ND',
 '21' = 'ND',
 '05' = 'ND',
 '13' = 'ND',
 '22' = 'ND',
 '06' = 'ND',
 '14' = 'ND',
 '23' = 'ND',
 '07' = 'ND',
 '15' = 'ND',
 '08' = 'ND',
 '16' = 'ND',
 '09' = 'ND',
 '17' = 'ND',
 '18' = 'ND',
 '19' = 'ND'
   }
};

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




Re: subroutine returning data

2012-06-04 Thread Chris Stinemetz
Thank you everyone. Your help has been very helpful..

Chris

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




Use of uninitialized value in length

2012-05-17 Thread Chris Stinemetz
Hello List,

I'm stumped on this one.

I'm getting this error:

Use of uninitialized value in length at ./DBSR.pl line 21,  line 6.
Use of uninitialized value in length at ./DBSR.pl line 21,  line 8.
Use of uninitialized value in length at ./DBSR.pl line 21,  line 10.
Use of uninitialized value in length at ./DBSR.pl line 21,  line 13.
Use of uninitialized value in length at ./DBSR.pl line 21,  line 16.
Use of uninitialized value in length at ./DBSR.pl line 21,  line 23.
Use of uninitialized value in length at ./DBSR.pl line 21,  line 25.

 I just want to skip to the next line of input data if any of the
array elements have no value (0 in length).

#!/usr/bin/perl
use warnings;
use strict;
use POSIX;
use Data::Dumper;

my $fileOut = testOut.txt;

open my $fin, '', $fileIn or die ERROR opening $fileIn: $!;
open my $out, '', $fileOut or die ERROR opening $fileOut: $!;

my @fields;

while(  ) {
  next unless /;/;
  chomp;
  my @data = split /;/;
  my($Icell,$Isect,$Ichan,$cfc,$cfcq,$rtd) = @data[9,10,27,36,37,40];
next if(length($Icell) == 0);
next if(length($Isect) == 0);
next if(length($cfc) == 0);
next if(length($cfcq) == 0);
next if(length($rtd) == 0);
$rtd = sprintf %.2f, $rtd/8/6.6/2;
push(@fields, $Icell,$Isect,$Ichan,$cfc,$cfcq,$rtd);
}
print Dumper \@fields;

Thank you,

Chris

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




array sorting

2012-05-17 Thread Chris Stinemetz
I have an array @fields that contains 6 elements.

I would like to sort the array by
$fields[0],$fields[1],$fields[2],$fields[3],$fields[4],$fields[5] in
ascending order starting witht he first element before I print the
array.

I haven't been able to figure this out. Any help is greatly appreciated.

Below is the program.

#!/usr/bin/perl
use warnings;
use strict;
use POSIX;
use Data::Dumper;

my $fileOut = testOut.txt;

open my $out, '', $fileOut or die ERROR opening $fileOut: $!;

my @fields;

while(  ) {
  next unless /;/;
  chomp;
  my @data = split /;/;
  my($Icell,$Isect,$Ichan,$cfc,$cfcq,$rtd) = @data[9,10,27,36,37,40];
if( $Icell = 1  $Isect = 1  $Ichan = 1  $cfc = 1 
$cfcq = 1  $rtd = 1) {
  $rtd = sprintf %.2f, $rtd/8/6.6/2;
  push(@fields, $Icell,$Isect,$Ichan,$cfc,$cfcq,$rtd);
} else {
next;
}

my @sorted_fields = sort { $a = $b } @fields;
print join(\t,@fields),\n;
@fields = ();
next;
}

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




Re: array sorting

2012-05-17 Thread Chris Stinemetz
Thank you Uri and Shawn.

I am getting the following error and not sure how to resolve:

I will also checkout the great suggestions Uri made.

Can't use string (3) as an ARRAY ref while strict refs in use at
./DBSRtest.pl line 51,  line 999.

#!/usr/bin/perl
use warnings;
use strict;
use POSIX;
use Data::Dumper;

# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent   = 1;

# Set maximum depth for Data::Dumper, zero means unlimited
local $Data::Dumper::Maxdepth = 0;

# configuration
my $fileOut = testOut.txt;
my $field_separator = quotemeta( ';' );

my $ICELL_INDEX =  9;
my $ISECT_INDEX = 10;
my $ICHAN_INDEX = 27;
my $CFC_INDEX   = 36;
my $CFCQ_INDEX  = 37;
my $RTD_INDEX   = 40;

my $fileIn = 
sprintf(/omp/omp-data/logs/pcmd/%s.PCMD,strftime(%y%m%d%H,localtime));
print $fileIn,\n;
#my $fileOut =
sprintf(/home/cstine/tools/DBSR/%s.txt,strftime(%y%m%d%H%M,localtime));

open my $fin, '', $fileIn or die ERROR opening $fileIn: $!;
open my $out, '', $fileOut or die ERROR opening $fileOut: $!;

#print Icell\t Isect\t Ichan\t cfc\t cfcq\t rtd\t;
my @fields;

while(  ) {
  next unless /;/;
  chomp;

  my @data = split /;/;
  my($Icell,$Isect,$Ichan,$cfc,$cfcq,$rtd) = @data[$ICELL_INDEX,
$ISECT_INDEX,  $ICHAN_INDEX,  $CFC_INDEX, $CFCQ_INDEX,  $RTD_INDEX];

if( $Icell = 1  $Isect = 1  $Ichan = 1  $cfc = 1 
$cfcq = 1  $rtd = 1) {
  $rtd = sprintf %.2f, $rtd/8/6.6/2;

  push(@fields, $Icell,$Isect,$Ichan,$cfc,$cfcq,$rtd);
  }
}


my @sorted_fields = sort {
 $a-[0] = $b-[0]
  || $a-[1] = $b-[1]
  || $a-[2] = $b-[2]
  || $a-[3] = $b-[3]
  || $a-[4] = $b-[4]
  || $a-[5] = $b-[5]
  } @fields;

print Dumper \@fields;


Thank you,

Chris

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




Re: Template toolkit issue

2012-05-02 Thread Chris Stinemetz
On Wed, May 2, 2012 at 8:29 AM, Mark Haney ma...@abemblem.com wrote:
 Okay, I've bit the bullet and started mucking with the perl template toolkit
 instead of mixing PHP and perl.  But I've hit a bizarre problem and I hope
 someone can point me to a fix.  I'm stumped.

 I've been following the base static and dynamic content generation tutorials
 and am fairly comfortable with things.  I just set up a dynamic script that
 generates the same page as my php code.  When I run the script from the
 command line (and the browser) I get correct HTML output /but/ the browser
 simply displays the code, it doesn't render it.

 When I manually run it and dump the HTML file into a folder and open it in a
 browser (on the same server mind you) I get the correct rendering of the
 page.

 So, what the devil am I missing?  I'll be glad to send my stuff to someone
 offlist to work on this, since it might be slightly OT, but I'll take any
 help I can get.


Are you getting any errors in the server error log? I would check there first.

HTH,

Chris

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




Perl for android

2012-04-02 Thread Chris Stinemetz
This maybe a silly question but is it possible to install Perl compiler on
a android device? Just curious.

Thanks,

Chris


Re: Use of uninitialized value in concatenation (.) or string

2012-03-28 Thread Chris Stinemetz

 It is always better to post a complete, short, working program rather than a
 snippet.


Maybe this will make it more clear as to what I am trying to
accomplish. I simply want to test to see if @hours exists as a second
key in the hash of hashes %data.
If it does not print \t otherwise print the value of the hash.

Sorrry still trying to wrap my head around iterating through a nested
referenced hash.

Thank you,

Chris

#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;



my %data =(

 '149' = {
'05' = '1',
'06' = '1',
'00' = '1',
'01' = '2',
'03' = '2',
'04' = '2'
  },
 '077' = {
'05' = 'ND',
'06' = 'ND',
'00' = 'ND',
'01' = 'ND',
'02' = 'ND',
'04' = 'ND'
  },
 '078' = {
'05' = '1',
'06' = '1',
'00' = '1',
'01' = '1',
'02' = '1',
'03' = '1',
  },

);

my $href = \%data;
my @wanted = qw(077 078 149);
my @hours = qw(00 01 02 03 04 05 06);


foreach my $cell ( @wanted ) {
  print  $cell:;
  foreach my $hr ( @hours ) {
if ( defined keys %{ $href-{$hr}}){
  print  \t$href-{$cell}{$hr};
}
else {
  print  \t;
}
  }
  print  \n;
}

output:
Use of uninitialized value in concatenation (.) or string at
./example.pl line 46.
077:ND  ND  ND  ND  ND  ND
Use of uninitialized value in concatenation (.) or string at
./example.pl line 46.
078:1   1   1   1   1   1
Use of uninitialized value in concatenation (.) or string at
./example.pl line 46.
149:1   2   2   2   1   1

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




Use of uninitialized value in concatenation (.) or string

2012-03-27 Thread Chris Stinemetz
Hello list,

I am getting the results I want with this iteration through the hash,
but I am stump on clearing the following warnings:

fyi line 12168 is the last line of the input file.

Use of uninitialized value in concatenation (.) or string at
./TESTdeltaT1.pl line 54, $SUM line 12168.
Use of uninitialized value in concatenation (.) or string at
./TESTdeltaT1.pl line 54, $SUM line 12168.
Use of uninitialized value in concatenation (.) or string at
./TESTdeltaT1.pl line 54, $SUM line 12168.
Use of uninitialized value in concatenation (.) or string at
./TESTdeltaT1.pl line 54, $SUM line 12168.
Use of uninitialized value in concatenation (.) or string at
./TESTdeltaT1.pl line 54, $SUM line 12168.
Use of uninitialized value in concatenation (.) or string at
./TESTdeltaT1.pl line 54, $SUM line 12168.
Use of uninitialized value in concatenation (.) or string at
./TESTdeltaT1.pl line 54, $SUM line 12168.

Any ideas on how to resove it?

code snippet:
51  foreach my $cell ( @wanted ) {
52print $DELTA $cell:;
53foreach my $hr ( @hours ) {
54  if ( defined keys %{ $href-{$hr}}){
55print $DELTA \t$href-{$cell}{$hr};
56  }
57  else {
58print $DELTA \t;
59  }
60}
61print $DELTA \n;
62  }

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




printing hashes

2012-03-25 Thread Chris Stinemetz
Below is snippet from Data::Dumper dump from a hash I have.

What is the best approach for only printing the hashes that have the
value 'ND' or hashes that have different values such as '149' does
below.

  '149' = {
 '05' = '1',
 '06' = '1',
 '00' = '1',
 '01' = '2',
 '02' = '2',
 '03' = '2',
 '04' = '2'
   },
  '077' = {
 '05' = 'ND',
 '06' = 'ND',
 '00' = 'ND',
 '01' = 'ND',
 '02' = 'ND',
 '03' = 'ND',
 '04' = 'ND'
   },
  '078' = {
 '05' = '1',
 '06' = '1',
 '00' = '1',
 '01' = '1',
 '02' = '1',
 '03' = '1',
 '04' = '1'
   },

Thank you ,

Chris

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




Re: printing hashes

2012-03-25 Thread Chris Stinemetz
Thank you.

How would I return the values along with the keys that meet the criteria
from the sub routine?

Thanks!

Chris
On Mar 25, 2012 10:04 AM, Rob Dixon rob.di...@gmx.com wrote:

 On 25/03/2012 14:11, Chris Stinemetz wrote:

 Below is snippet from Data::Dumper dump from a hash I have.

 What is the best approach for only printing the hashes that have the
 value 'ND' or hashes that have different values such as '149' does
 below.

   '149' =  {
  '05' =  '1',
  '06' =  '1',
  '00' =  '1',
  '01' =  '2',
  '02' =  '2',
  '03' =  '2',
  '04' =  '2'
},
   '077' =  {
  '05' =  'ND',
  '06' =  'ND',
  '00' =  'ND',
  '01' =  'ND',
  '02' =  'ND',
  '03' =  'ND',
  '04' =  'ND'
},
   '078' =  {
  '05' =  '1',
  '06' =  '1',
  '00' =  '1',
  '01' =  '1',
  '02' =  '1',
  '03' =  '1',
  '04' =  '1'
},


 Hi Chris

 The program below puts the keys of the hash elements that pass your
 criteria into @wanted.

 Hope it helps,

 Rob


 use strict;
 use warnings;

 my $href = {
  '149' = {
 '05' = '1',
 '06' = '1',
 '00' = '1',
 '01' = '2',
 '02' = '2',
 '03' = '2',
 '04' = '2'
   },
  '077' = {
 '05' = 'ND',
 '06' = 'ND',
 '00' = 'ND',
 '01' = 'ND',
 '02' = 'ND',
 '03' = 'ND',
 '04' = 'ND'
   },
  '078' = {
 '05' = '1',
 '06' = '1',
 '00' = '1',
 '01' = '1',
 '02' = '1',
 '03' = '1',
 '04' = '1'
   },
 };

 sub ND_or_multiple {
  my %uniq;
  for (values %{$href-{$_[0]}}) {
return 1 if $_ eq 'ND';
$uniq{$_}++;
return 1 if keys %uniq  1;
  }
  return '';
 }

 my @wanted = grep ND_or_multiple($_), keys %$href;

 print map $_\n, @wanted;

 **OUTPUT**

 149
 077



Re: printing hashes

2012-03-25 Thread Chris Stinemetz

 Keeping with the use of $_, replace the following 'print map' statement to
 the following:


 print map $_\n, @wanted;


 foreach ( @wanted ){
    print $_:\n;
    foreach ( values %{ $href-{ $_ } } ){
       print \t$_\n;
    }
 }

 ** OUTPUT **

 149:
        2
        2
        1
        1
        1
        2
        2
 077:
        ND
        ND
        ND
        ND
        ND
        ND
        ND


I'm getting this error that I'm not sure how to fix:

$ ./datalink.pl   out.txt
Can't use string (389/1024) as a HASH ref while strict refs in use
at ./datalink.pl line 41, $SUM line 4060.

code snippet:
my $href = %data;

sub ND_or_multiple {
  my %uniq;
  for (values %{$href-{$_[0]}}) {
 return 1 if $_ eq 'ND';
 $uniq{$_}++;
 return 1 if keys %uniq  1;
  }
  return '';
}

my @wanted = grep ND_or_multiple($_), keys %$href;   # -- line 41

foreach ( @wanted ) {
  print $_:\n;
  foreach (values %{ $href-{ $_ } } ){
print \t$_\n;
  }
}

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




Re: printing hashes

2012-03-25 Thread Chris Stinemetz
 code snippet:
 my $href = %data;


I changed  my $href = %data; to my $href = \%data; and it works now.

Thanks all,

Chris

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




Re: printing hashes

2012-03-25 Thread Chris Stinemetz
On Mar 25, 2012 11:15 AM, Steve Bertrand steve.bertr...@gmail.com wrote:

 On 2012-03-25 12:02, Chris Stinemetz wrote:

 How would I return the values along with the keys that meet the criteria
 from the sub routine?


 On Mar 25, 2012 10:04 AM, Rob Dixonrob.di...@gmx.com  wrote:


 Keeping with the use of $_, replace the following 'print map' statement
to the following:


 print map $_\n, @wanted;


 foreach ( @wanted ){
print $_:\n;
foreach ( values %{ $href-{ $_ } } ){
   print \t$_\n;
}
 }

 ** OUTPUT **

 149:
2
2
1
1
1
2
2
 077:
ND
ND
ND
ND
ND
ND
ND


Any advice on how to include a numerical sort on the second key? I've been
trying to resolve this for a while and have had no luck.

Thank you,

Chris


Re: printing hashes

2012-03-25 Thread Chris Stinemetz

 Use a block sort to sort numerically:

 perl -E '%h=qw(3 a 2 b 1 c 4 d); say sort { $a=$b } keys %h;'

 Show us what you have so far if you need help with a specific code segment.


references are still a bit foreighn to me. Below is the error I am
getting along with the snippit of code.

Can't use string (ND) as a HASH ref while strict refs in use at
./datalink.pl line 48, $SUM line 4060.

my $href = \%data;

sub ND_or_multiple {
  my %uniq;
  for (values %{$href-{$_[0]}}) {
 return 1 if $_ eq 'ND';
 $uniq{$_}++;
 return 1 if keys %uniq  1;
  }
  return '';
}

my @wanted = grep ND_or_multiple($_), sort  keys %$href;

foreach my $cell ( @wanted ) {
  print $cell:;

  foreach my $hr ( sort keys %{ $href-{$cell}} ) {
# print \t$hr;
foreach my $count ( sort keys %{ $href-{$cell}-{$hr}} ) { # -- line 48
print \t$count;
}
  }
  print \n;
}

Thank you,

Chris

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




Re: printing hashes

2012-03-25 Thread Chris Stinemetz

 replace all of this:


   foreach my $hr ( sort keys %{ $href-{$cell}} ) {
     # print \t$hr;
     foreach my $count ( sort keys %{ $href-{$cell}-{$hr}} ) { #-- line
 48
     print \t$count;
     }
   }


 ...with this:


    foreach my $hr ( sort keys %{ $href-{$cell}} ) {
        print \t$hr $href-{$cell}{$hr};
    }

 and see if it fixes your problem. Here is the output. If it is not what you
 desire the output to be, just say so. If it is, let us know. Once we get it
 sorted, I'll try to explain why it was breaking :)

 Output:

 149:    00 1    01 2    02 2    03 2    04 2    05 1    06 1
 077:    00 ND   01 ND   02 ND   03 ND   04 ND   05 ND   06 ND

 Steve

That works perfectly! Thank you.

Please explain where mine was breaking.

Thank you,

Chris

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




Re: printing hashes

2012-03-25 Thread Chris Stinemetz
 If there is anything I didn't explain well, just say so.

 Good job on your attempts.

 Steve


Thank you very much! I am very grateful for your help and explanations.

Take care,

Chris

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




Re: some suggestions

2012-03-23 Thread Chris Stinemetz
Thank you everyone. I'm still digesting this, but I do have a better
understanding.

Chris

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




Re: Why do I get a warning?

2012-03-22 Thread Chris Stinemetz
On Thu, Mar 22, 2012 at 2:47 PM, Manfred Lotz manfred.l...@arcor.de wrote:
 Hi all,
 If I run the following small test snippet

 --snip
 #! /usr/bin/perl

 use strict;
 use warnings;

 use autodie;



 open my $hdl, , fileio1.txt;
 print $hdl a line\n;
 close $hdl;

 open HDL, , fileio2.txt;
 print HDL a line\n;
 close HDL;
 --snap


 I get the message:
 Name main::HDL used only once: possible typo at ./fileio1.pl line 16.


It looks like you are tyring to open two different filehandles. You
need to delcare HDL.
open my $HDL, '', fileio2.txt;

should fix it.

HTH,

Chris

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




some suggestions

2012-03-22 Thread Chris Stinemetz
I would like to use the number on the left as a key in a hash and use
the number on the right as the value pair to the key. Then print the
values for each hour that have the same key. Maybe this is a good
example for an array of hashes, but I not real sure how to begin. Any
help is greatly appreciated.

Below is the input data:

Hr 12
0001 2
0002 3
0003 1
Hr 13
0001 2
0002 3
0003 1
Hr 14
0001 2
0002 3
0003 1

Desired output below:

  12 13 14
00012   2  2
00023   3  3
00031   1  1

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




count regex match

2012-03-21 Thread Chris Stinemetz
I would like to count the number of regex match and then move onto the
 next iteration in the loop, I'm not able to get this program to work
as intended.

my $cell;
my $count = 0;
my $link;
my @linkCount;

print $file,\n;

while (my $line = ) {
  if ($line =~ /HCS\s(\d+)/) {
  $cell = $1;

  if ($line =~ /DL_UPLINK_AVG_THRUPUT,\s\d+/) {
  $count++;
  next;
  }

  push(@linkCount,$count);
  }
}

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




POSIX

2012-03-21 Thread Chris Stinemetz
Is there a way to take localtime less two hours? So there is an offset of 2?

example line:

my $file = sprintf($dirPath%s00.HCSFMS023,strftime(%Y%m%d%H,localtime ));

Thank you,

Chris

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




comparing values in two hashes

2012-03-17 Thread Chris Stinemetz
Hello list,

I have two hashes that I would like to compare the values where the
keys are the same. If there are any discrepancies I would like to
print them. I have been struggling in find a solution. Below is what I
have thus far:

#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;

my $firstFile = out.txt;
my $secFile = outADD.txt;
my $deltaFile = datalinkDeltas.txt;

open my $firstFH,'',$firstFile or die ERROR opening $firstFile: $!;
open my $secFH,'',$secFile or die ERROR opening $secFile: $!;
open my $deltaFH,'',$deltaFile or die ERROR opening $deltaFile: $!;

my %firstFile;
my %secondFile;

while (my $line = $firstFH) {
my ($k,$v) = split(/\s/,$line);
$firstFile{$k} = $v;
}

while (my $line = $secFH) {
my ($k,$v) = split(/\s/,$line);
$secondFile{$k} = $v;
}
print Dumper (\%firstFile,\%secondFile);

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




Re: multiple pattern matching

2012-03-08 Thread Chris Stinemetz
On Thu, Mar 8, 2012 at 11:03 AM,  sunita.prad...@emc.com wrote:
 Hi All

 I have one output of one my command like :

 $output = Step 155 of 171 
 steps.Executing.
    Step 168 of 171 steps.Executing.
    Step 171 of 171 steps.Executing.
    Local:  COMMITDone.

      New symdev:  2552
      New symdev:  2553
    Terminating the configuration change session..Done. ;

 I need to get those numbers like 2552 , 2553 .

 I am applying following patter matching logic but it does not get me the  1st 
 number (2552) .

 @devs = $output =~ m/New symdev:\s*([0-9A-Fa-f]{4})/gis;
                        print $output,\n;
                        print Devices  @devs \n;


 Could you please check what is going  wrong in  the above lines ?


My approach would be to read it line by line with a while loop. There
may be a better way of achieving your goal.

#!/usr/bin/perl
use warnings;
use strict;

while ( DATA ) {
  if ( $_ =~ m/New symdev:\s+(\d+)/ ) {
print $1\n;
  }
}


__DATA__
my $output = Step 155 of 171
steps.Executing.
   Step 168 of 171 steps.Executing.
   Step 171 of 171 steps.Executing.
   Local:  COMMITDone.

 New symdev:  2552
 New symdev:  2553
   Terminating the configuration change session..Done. ;

###OUTPUT###
2552
2553

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




Re: problem with nested regex matchs

2012-03-07 Thread Chris Stinemetz
Hello Shanmugam,

Please start a new thread when you post a new topic.


On Wed, Mar 7, 2012 at 5:14 PM, shanmugam m bluepulse5...@gmail.com wrote:
 Hi,
  This is my first perl program..I'm getting wired errors.Please take a
 look.


 #!persist/pkg/bin/perl
 use diagnostics;
 use warnings;

always use the strict pragma especially when you are learning Perl.
This will help you understand what is going on and also enforce you to
use better programming practices such as lexical scope.
use strict;


 open(MYINPUTFILE ,/net/fallsroot/export/d100/m4/input_file);
 open(MYOUTFILE,  output_file);

it is recommended to use a three argument filehandle
open my $INPUTFILE, '',$input_file or die ERROR opening $input_file: $!;
open my $OUTFILE, '',$output_file or die ERROR opening $output_file: $!;


 foreach $line (MYINPUTFILE){

use a while loop to read one line at a time
while ( my $line = $INPUTFILE ) {
chomp $line;


    chomp($line);                    # remove the newline from $line.
                                     # do line-by-line processing.
    my @column1 = split(/\\/,$line);
I'm not sure what you are trying to do here. Split will split on white
space by default

    print MYOUTFILE $column1[5] ,\t ;
you are trying to print the fifth element in the array @column1

    my @column2 = split(=,$line);
now it looks like you are wanting to split $line again based on =
this would require you to reread the input file or create a better
regex to capture everything you want in the first read

    print MYOUTFILE $column2[1]  ,\n ;

    }

 close(MYOUTFILE);
 Regards,
 Shanmugam


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




Re: problem with nested regex matchs

2012-03-07 Thread Chris Stinemetz
correction
 while ( my $line = $INPUTFILE ) {
should be:
while ( my $line = $INPUTFILE ) {

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




Re: problem with nested regex matchs

2012-03-07 Thread Chris Stinemetz


 open(MYINPUTFILE ,/net/fallsroot/export/d100/m4/input_file);
 open(MYOUTFILE,   output_file);


 it is recommended to use a three argument filehandle


 three argument filehandle?

What I meant to imply was: 3-argument version of open



 open my $INPUTFILE, '',$input_file or die ERROR opening $input_file:
 $!;
 open my $OUTFILE, '',$output_file or die ERROR opening $output_file:
 $!;


 foreach $line (MYINPUTFILE){


 use a while loop to read one line at a time
 while ( my $line = $INPUTFILE ) {
     chomp $line;


    chomp($line);                    # remove the newline from $line.
                                     # do line-by-line processing.
    my @column1 = split(/\\/,$line);

 I'm not sure what you are trying to do here. Split will split on white
 space by default

    print MYOUTFILE $column1[5] ,\t ;

 you are trying to print the fifth element in the array @column1


 Array indexes start at 0 so that is the sixth element.

You are correct. This was a careless response on my part.




    my @column2 = split(=,$line);

 now it looks like you are wanting to split $line again based on =
 this would require you to reread the input file or create a better


 Why would you need to reread the input file?

How would you handle this?
The OP didn't provide the input data.



Chris

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




Re: strict subs in use at -e line 1.

2012-03-06 Thread Chris Stinemetz
On Tue, Mar 6, 2012 at 9:31 AM, lina lina.lastn...@gmail.com wrote:
 $ perl -Mstrict -wle '{my $char = chr(Ox394) ; print $char;}'

 Bareword Ox394 not allowed while strict subs in use at -e line 1.
 Execution of -e aborted due to compilation errors.

 I don't understand the above error message well,

 Thanks ahead for any explainations,

 Best Regards,

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



If you are simply trying to assign chr(0x394) to varible $char and
then print $char then the below will work.

perl -Mstrict -wle '{my $char = chr(0x394) ; print $char;}'


HTH,

Chris

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




search and replace with an array

2012-02-20 Thread Chris Stinemetz
I am trying ot find a way to use an array as a reference to remove
lines from a file.
The array @keyFields has the elements rcsm and cdmno. My objective
is to remove any line from the input that matches the regex /rcsm\d/
and cdmno\d/.

I'm not sure if I'm using the best approach.

I am getting the following error:

Argument rcsm isn't numeric in array element at deleteData1.pl line
15, DATA line 1.
Argument cdmno isn't numeric in array element at deleteData1.pl line
15, DATA line 1.

#!/usr/bin/perl
use warnings;
use strict;

my $file = nonKeys.txt;
my $newFile = cleanKeys.txt;
my @keyFields = qw(rcsm cdmno);

#open my $FH, '', $file or die ERROR opening $file: !;
open my $FHOUT, '', $newFile or die ERROR opening $newFile: !;

while ( DATA ) {
  chomp;
  for my $i ( @keyFields ) {
print $FHOUT $_ =~ s/$keyFields[$i]\d/match/;
  }
}

__DATA__
cdmno=1
rdnt_cdmno=1
cdmno2=1
cdmno3=1
cdmno4=1
cdmno5=1
cdmno6=1
cdmno7=1
cdmno8=1
cdmno=2
rcsm=801
rcsm2=801
rcsm3=801
rcsm4=801
rcsm5=801
rcsm6=801
rcsm7=801
rcsm8=801
rcsm=801
rcsm2=801
rcsm3=801
rcsm4=801
rcsm5=801
rcsm6=801
rcsm7=801
rcsm8=801
rcsm=802

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




Re: search and replace with an array

2012-02-20 Thread Chris Stinemetz
Looks like I was able to figure it out with the below:

But how do I remove all the blank lines?

Output:

cdmno=1
rdnt_cdmno=1







cdmno=2
rcsm=801







rcsm=801







rcsm=802

#!/usr/bin/perl
use warnings;
use strict;

my $file = nonKeys.txt;
my $newFile = cleanKeys.txt;
my @keyFields = qw(rcsm cdmno);

#open my $FH, '', $file or die ERROR opening $file: !;
open my $FHOUT, '', $newFile or die ERROR opening $newFile: !;

while ( DATA ) {
  chomp;
  for my $i ( 0 .. $#keyFields ) {
$_ =~ s/$keyFields[$i]\d.*//;
  }
  print $_\n;
}
__DATA__
cdmno=1
rdnt_cdmno=1
cdmno2=1
cdmno3=1
cdmno4=1
cdmno5=1
cdmno6=1
cdmno7=1
cdmno8=1
cdmno=2
rcsm=801
rcsm2=801
rcsm3=801
rcsm4=801
rcsm5=801
rcsm6=801
rcsm7=801
rcsm8=801
rcsm=801
rcsm2=801
rcsm3=801
rcsm4=801
rcsm5=801
rcsm6=801
rcsm7=801
rcsm8=801
rcsm=802

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




Re: search and replace with an array

2012-02-20 Thread Chris Stinemetz
Thank you everyone that replied.

Your suggestions helped me with finding a solution.

Take care,

Chris

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




Re: looping through an array with for

2012-02-15 Thread Chris Stinemetz
Thank you Jim.

Your suggestions worked perfectly!

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




looping through an array with for

2012-02-14 Thread Chris Stinemetz
I have a for loop I would like to alter so that when the iteration
reaches the last element in the array the varibale $lastmatch is
passed to printf instead of $match.

Does anyone have any suggestions?

my $match = GE 0 AND ;
my $lastmatch = GE 0;

for my $i (0 .. $#keyFields) {
  printf %s %s, $keyFields[$i], $match,;
}

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




Re: Parsing a microarray data file

2012-01-26 Thread Chris Stinemetz
Hello Tiago,

On Thu, Jan 26, 2012 at 11:08 AM, Tiago Hori tiago.h...@gmail.com wrote:
 Hi All,

 I need some help to get started on a script.

 I have these huge data files 16K rows and several columns. I need to parse
 the rows into a subset of these 16K rows. Each rows has a identifier made
 up of 2 letters and 6 numbers and the ones I want have specific letter,
 they start with either C or D. So I know I can use regex, but I have been
 trying to figure out the rest and I don't know where to start. This is the
 first time I am trying to do something from scratch so any suggestions
 would be appreciated. I am not asking for the script but just some help on
 how to go about it.

 So, what I want to be able to do is retrieve all the rows that have
 identifiers starting with C or D. Should I use arrays, can I store each row
 as one item a (set of information separated by tabs) in an array?


Yes I would use an array to store the data and then use regex to
extract the rows based on your criteria.

I put together a little sample program using fictitious data. You
should be able to apply the same concept to your needs.

***tested***

#!/usr/bin/perl
use warnings;
use strict;

while ( DATA ) {
  chomp;
  my @array = split;
  my $GeneID = $array[6];

  if ($GeneID =~ /^C|D/) {
print $_,\n;
  }
}

__DATA__
Line1 c 2 3 4 5 C 7 8 9
Line2 1 2 3 4 5 6 7 8 9
Line3 1 2 3 4 5 D 7 8 9
Line4 1 2 3 4 5 6 7 8 9
Line5 1 2 3 4 5 D 7 8 9
Line6 1 2 3 4 5 6 7 8 9

***output***
Line1 c 2 3 4 5 C 7 8 9
Line3 1 2 3 4 5 D 7 8 9
Line5 1 2 3 4 5 D 7 8 9

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




Re: Parsing a microarray data file

2012-01-26 Thread Chris Stinemetz
 ***tested***

 #!/usr/bin/perl
 use warnings;
 use strict;

 while ( DATA ) {
  chomp;
  my @array = split;
  my $GeneID = $array[6];

  if ($GeneID =~ /^C|D/) {

I'm still learning regex but it could be better written with;
if ($GeneID =~ /^[CD]/) {

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




Schwartzian Transform

2012-01-17 Thread Chris Stinemetz
Would someone kindly advise me in sorting this array:

my @array = qw(c r v vr tr re c.p[1] c.p[3] c.p[2] c.p[4] c.p[7]
c.p[6] c.p[5] c.p[8] c.t[1] c.t[3] c.t[2]);

I only want to sort the elements that have a numeric value inside the
braces so that all the other elements have their original index
preserved.

Sample output I am trying to accomplish:

c
r
v
vr
tr
re
c.p[1]
c.p[2]
c.p[3]
c.p[4]
c.p[5]
c.p[6]
c.p[7]
c.p[8]
c.t[1]
c.t[2]
c.t[3]

Is this a good example to use Schwartzian Transform?

Thanks in advance,

Chris

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




Re: comparing arrays

2012-01-12 Thread Chris Stinemetz
Thanks for your advice Jim.

Although it makes very good sense to me, I am having a little
difficult implementing it. I will have to admit referencing is still a
bit foreign to me.

I am getting the following error and I am not sure how to fix it.

Type of arg 1 to push must be array (not reference constructor) at
./headers.pl line 11, near $setref)
Execution of ./headers.pl aborted due to compilation errors.


### SCRIPT ###

#!/usr/bin/perl
use warnings;
use strict;

use Data::Dumper;

my %seen;
my @header;
my @data;
my $setref = {};
push(\@data,$setref);
my $delim = ,;

while(DATA) {
  chomp;

  if(/(.*)=(.*)/) {
$seen{$1}++;
$setref-{$1} = $2;

if ($seen{$1} == 1) {
  push(@header,$1);
}
  }

  elsif(/^\s*$/) {
push(@data,$setref);
print Dumper \@data;
  }
}

print join($delim,@header),\n;


__DATA__
csno=1
rfpi=1
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
row[1]=yes
rfpc0=0
rfpc1=0

csno=1
rfpi=2
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
row[4]=no
rrl=20
rfpc0=0
rfpc1=0

csno=1
rfpi=3
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
rfpc0=0
rfpc1=0

csno=2
rfpi=1
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
line=yes
rfpc0=0
rfpc1=0

csno=2
rfpi=2
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
rfpc0=0
line=value
row[15]=
tti=1
rfpc1=0

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




Re: comparing arrays

2012-01-12 Thread Chris Stinemetz
Thank you Jim. That got me over that hurdel!

Any advice on how to maintain the order of elements in the @header
array and print the value to the right of the = sign for each
dataset, and if there is a value in the dataset that doesn't match the
element in the @header simply leave the value blank?

so the output looks like:

Thanks again for all your help.

Chris

csno,rfpi,vrp0,vrp1,trl,repl,repl_d1,rrl,row[1],rfpc0,rfpc1,row[4],line,row[15],tti
1,1,3423000,3423000,170,100,100,20,yes,0,0
1,2,3423000,3423000,170,100,100,,,0,0
1,3,3423000,3423000,170,100,100,20,,,
2,1,3423000,3423000,170,100,100,20,,0,0
2,2,3423000,3423000,170,100,100,20,,,

updated script

#!/usr/bin/perl
use warnings;
use strict;

use Data::Dumper;

my %seen;
my @header;
my @data;
my $setref = {};
push(@data,$setref);
my %headers;
my $delim = ,;

while(DATA) {
  chomp;

  if(/(.*)=(.*)/) {
$seen{$1}++;
$setref-{$1} = $2;
$headers{$1}++;

if ($seen{$1} == 1) {
  push(@header,$1);
}
  }

  elsif(/^\s*$/) {
$setref = {};
push(@data,$setref);
  }
}

print join($delim,@header),\n;

print Field counts:\n\n;
for my $key ( @header ) {
   printf(  %6s  %3d\n, $key,$headers{$key} ); }



__DATA__
csno=1
rfpi=1
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
row[1]=yes
rfpc0=0
rfpc1=0

csno=1
rfpi=2
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
row[4]=no
rrl=20
rfpc0=0
rfpc1=0

csno=1
rfpi=3
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
rfpc0=0
rfpc1=0

csno=2
rfpi=1
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
line=yes
rfpc0=0
rfpc1=0

csno=2
rfpi=2
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
rfpc0=0
line=value
row[15]=
tti=1
rfpc1=0

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




Re: comparing arrays

2012-01-12 Thread Chris Stinemetz

 Define an array with the headers you expect:

 my @headers = ( 'csno', 'rfpi', 'vrp0', ... );

 Use that array for your keys instead of the @header array.

 To avoid warnings of uninitialized values for missing values, print the
 expression (defined $data{$key} ? $data{$key} : '' ) instead of $data{$key}
 or put no warnings 'unintialized'; inside the print loop.


Thanks again Jim,

I am having a bit of trouble trying to implement your suggestions.

I am getting the following error:

Global symbol %data requires explicit package name at
C:\Users\cstinemetz\Documents\Perl\dev\headers.pl line 38.
Global symbol %data requires explicit package name at
C:\Users\cstinemetz\Documents\Perl\dev\headers.pl line 38.

I believe it is because (defined $data{$key} ? $data{$key} : '' ) is
for hash notation and not array.

I also kept the @header array because it contains all the elements
that I am expecting to be in the header.

Thanks again for your help.

It is greatly appreciated,

Chris

#!/usr/bin/perl
use warnings;
use strict;

use Data::Dumper;

my %seen;
my @header;
my @data;
my $setref = {};
push(@data,$setref);
my %headers;
my $delim = ,;

while(DATA) {
  chomp;

  if(/(.*)=(.*)/) {
$seen{$1}++;
$setref-{$1} = $2;
$headers{$1}++;

   if ($seen{$1} == 1) {
  push(@header,$1);
}
  }

  elsif(/^\s*$/) {
$setref = {};
push(@data,$setref);
  }
}

# header
print join($delim,@header),\n;

for my $key (@header) {
  (defined $data{$key} ? $data{$key} : '' )
  print join($delim,@data),\n; }

__DATA__
csno=1
rfpi=1
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
row[1]=yes
rfpc0=0
rfpc1=0

csno=1
rfpi=2
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
row[4]=no
rrl=20
rfpc0=0
rfpc1=0

csno=1
rfpi=3
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
rfpc0=0
rfpc1=0

csno=2
rfpi=1
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
line=yes
rfpc0=0
rfpc1=0

csno=2
rfpi=2
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
rfpc0=0
line=value
row[15]=
tti=1
rfpc1=0

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




comparing arrays

2012-01-11 Thread Chris Stinemetz
I have a script where I have captured the value on the left side of
the = as the header for my table. Now I want to take the value on
the right side of the = sign and populate a new row in table format
where the header value I stored in the @header array matches the value
on the left side of the = sign. Each dataset begins with a new line.
If there is no match I would like to return null or just  as the
value.

Below is the script thus far.

Any advice is greatly appreciated,

Chris

currently my output is just the header. I haven't been able to figure
out how to do the rest.

**OUTPUT**
csno,rfpi,vrp0,vrp1,trl,repl,repl_d1,rrl,row[1],rfpc0,rfpc1,row[4],line,row[15],tti


#!/usr/bin/perl
use warnings;
use strict;

my %seen;
my @header;
my $delim = ,;

while( DATA ) {
  chomp;

  if($_ =~ /(.*)\=(.*)?/) {
$seen{$1}++;

if ($seen{$1} == 1) {
  push(@header,$1);
}
  }
}

print join( $delim,@header ),\n;


__DATA__
csno=1
rfpi=1
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
row[1]=yes
rfpc0=0
rfpc1=0

csno=1
rfpi=2
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
row[4]=no
rrl=20
rfpc0=0
rfpc1=0

csno=1
rfpi=3
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
rfpc0=0
rfpc1=0

csno=2
rfpi=1
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
line=yes
rfpc0=0
rfpc1=0

csno=2
rfpi=2
vrp0=3423000
vrp1=3423000
trl=170
repl=100
repl_d1=100
rrl=20
rfpc0=0
line=value
row[15]=
tti=1
rfpc1=0

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




Re: array uniq elements

2012-01-09 Thread Chris Stinemetz
Thank you Jim. Your advice worked perfectly.

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




array uniq elements

2012-01-08 Thread Chris Stinemetz
How do I extract uniq elements from an array? Basically I want to
preserve the order of the elements as they are first seen, but I would
like to remove any duplicates.

Below is what I have so far.

Thank you in advance.

Chris

#!/usr/bin/perl
use warnings;
use strict;

use Data::Dumper;

my @header;

while( DATA ) {
  chomp;

  if($_ =~ /(.*)\=(.*)?/) { will use $2 for later.
@header = $1;
print Dumper \@header;
  }
}


__DATA__
csno=1
rfpi=1
vrp0=3423000
vrp1=3423000
trl=170
low=
high=5

csno=1
rfpi=2
vrp0=3423000
vrp1=3423000
trl=170
row[1]=
row[2]=
row[3]=
line=
low=
high=5

csno=1
rfpi=3
vrp0=3423000
vrp1=3423000
trl=170
line=
low=
line[1]=
line[2]=
high=5
low=

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




Re: Hello a question about .+?

2011-12-29 Thread Chris Stinemetz
On Thu, Dec 29, 2011 at 1:17 PM, Xi Chen cxde...@gmail.com wrote:
 Hello everyone,

 I have a question about how to translate the meaning of .+?. Please
 see the examples below:
 SASI_Hs01_00205058      HUMAN   NM_005762       857     MISSION¬Æ siRNA 2     
                    140.00
 I want to get number857, I found the command below works:
 perl -ne 'if (/(SASI\w+)(.+?)\s(\d+)\s/) { print $3\n; }'
 but .+ or .*doesn't work. I don't know why ? is so important?


I believe it makes the grouping optional.

Match 1 or 0 times

HTH,

Chris

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




Re: What does = means?

2011-12-29 Thread Chris Stinemetz
On Thu, Dec 29, 2011 at 9:26 PM, Xi Chen cxde...@gmail.com wrote:
 Hello everyone,

 I saw a code below to get two same letters p in @a.

 @a = qw (D D p O H p A O);
 foreach $b (@a){
 $n =~ /$b/i;
 if($n = 2){
     $m = $b;
    }
 }

 But I don't know what does = mean. Thank you!


It is just geater than equal to inside an if condition

Chris

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




  1   2   >