Re: What is the difference between () and [] syntax for array?

2013-01-07 Thread Parag Kalra
On Mon, Jan 7, 2013 at 5:33 PM, Neo Anderson neo_in_mat...@msn.com wrote:

  my @a1 = (1, 2, 3);


Here we are actually storing the elements into the array.


 my @a2 = [1, 2, 3];


And in this case we are storing the reference to the array containing
elements 1, 2 and 3.

This should actually be: my $a2 = [1, 2, 3];

And to store the elements: my @a2 =  @{$a2};

Thanks,
Parag


How to send RPCs to a Network server using Perl

2012-09-06 Thread Parag Kalra
I am planning to design a simple client application to execute RPC (Remote
Procedure Call) on a remote server.

All I have managed to learn so far is to create a TCP socket using
IO::Socket::INET.

But I am not sure what to do next.

Any pointers/help/online resources about the same would be helpful.

Thanks,
Parag


Question on the function - hex

2012-04-12 Thread Parag Kalra
Why does the output of
perl -e print hex '0x160402'

differs from the output of
perl -e print hex 0x160402

EG:
bash-3.2$ perl -e print hex '0x160402'
94489281538

$ perl -e print hex 0x160402
10189963531576


Re: Introduction and Perl 5 References

2012-02-27 Thread Parag Kalra
On Mon, Feb 27, 2012 at 5:02 PM, Mike ekimduna...@gmail.com wrote:

 Hello everyone.


Hi


 I just wanted to introduce myself to the list. Been following for a little
 while, first time posting. My name is Mike Dunaway and I am 25 years old. I
 was curious if there were any other members in the 804 area?


Do you mean, phone area code of 804?. See if this helps

http://www.pm.org/groups/united_states_of_america.html



 Would anyone mind explaining references to me like I was five years old?


 References are like pointers in C. References can be created to different
data structures like scalars, arrays, hashes, subroutines etc.

And they can be created using a back-slash (\)

EG:

my $var = 'FooBar';
my @arr = ('Hello', 'World');

So if you wanted to create a reference to $var or @arr, you can do it in
following way:

my $ref_to_scalar = \$var;
or
my $ref_to_array = \@arr;

Now if you want to print the data structures through references, one of the
way is:

print Value of scalar: ${$ref_to_scalar}\n;
print Elements of array: @{$ref_to_array}\n;

I read about them in Beginning Perl, but I can't quite grasp them very
 well. Thanks!


I would strongly recommend to read it again. My advice - Do not advance to
next chapter till you understand the current chapter.

It's one of the best books on Perl and highly recommended for beginners.

HTH

Cheers,
Parag


Perl Module to parse any other Perl script/module to fetch stats about data-structures

2012-02-08 Thread Parag Kalra
Do we have any Perl module which can parse any other perl script (or
module) and fetch information like total number of arrays being used, total
number of hashes, total number of scalar variables etc and size information
 (like total elements, total keys etc) for each data structure in that perl
script or may be another perl module

Thanks,
Parag


Re: Perl Module to parse any other Perl script/module to fetch stats about data-structures

2012-02-08 Thread Parag Kalra
By data-structures being used, I mean the data structures that are actually
*declared* in the script.

And is it possible to find at least the data-structures stats of the
current script that is getting executed if no parser is available.

For example if I have a big script or module and if I want to find total
arrays, hashes and variables declared in that script. Is there any special
variable where this info is stored.

Thanks,
Parag

On Wed, Feb 8, 2012 at 6:31 PM, Jeff Peng p...@staff.dnsbed.com wrote:

 于 2012-2-9 10:15, Steve Bertrand 写道:


 I would suspect that this would be something that would have to run
 against the file itself, even prior to compile.

 Curious task. Might I ask what the purpose of your desire is?


 I am also not sure what's the special purpuse of the OP.
 Some modules on CPAN under the namespace of Devel::* may help him.

 Jeff.

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





Re: Foreach loop and hash of arrays

2012-02-06 Thread Parag Kalra
On Mon, Feb 6, 2012 at 1:14 PM, sono...@fannullone.us wrote:

For example, do I really need three foreach loops?




You can get rid of third ForLoop for sure.

use strict;
use warnings;

my %states = (
   AL = [ '350','351', ],
   AK = [ '995','996', ],
   AZ = [ '850','851', ],
   AR = [ '716','717', ],
);

my $customers_state = 'AZ';
my $customers_zip = '850';
my $match = 'no' ;

STATE: foreach my $state (keys %states) {
   if ($state eq $customers_state) {
   foreach (@{$states{$customers_state}}) {
   my @zips = $_;
   $match = 'yes' if grep /$customers_zip/, @zips ;
   last STATE;
   }
   }
}
print $match;


Re: syntax error near unexpected token `;'

2012-02-06 Thread Parag Kalra
On Mon, Feb 6, 2012 at 8:35 PM, lina lina.lastn...@gmail.com wrote:

 until ($name eq );
 do {
print Enter another name, or Enter to stop:\n ;
$name = STDIN;
chomp ($name);
push @namelist,$name;

 }

 print @namelist


This should work. Also start using strict and warnings pragma.

do {
   print Enter another name, or Enter to stop:\n ;
   $name = STDIN;
   chomp ($name);
   push @namelist,$name;

}until ($name eq );

print @namelist


Inserting a new data structure in a bless reference

2012-01-13 Thread Parag Kalra
The simplest way I thought of expressing this question is through
Pseudo-script so here it is:

use strict;
use warnings;
use FooBar;

my $obj = FooBar-new;


Do something

...
$obj-{'new_key'} = 'some_value'

Now I am not sure if that is the correct way of inserting a new data
structure into an already bless reference

My aim to use this data structure across the script and FooBar through the
object -$obj once added.


Customizing vi/vim for Perl

2011-11-18 Thread Parag Kalra
Hi,

I generally use vi/vim for my day to day Perl scripts.

What are different packages I can use to make vi/vim extensively customized
for Perl.  For example -  it should be able inform me about the known
syntax errors like - variables not declared, missing braces or semicolons
etc something which Eclipse done.

And who has more customization packages for Perl - vi or Emacs?

Parag


Perl variable indirection

2011-11-05 Thread Parag Kalra
Hi,

I have a function which looks something like:

sub foo_bar {
${$_[0]} = new foo_bar (
  address = $_[1],
  sudo= $_[3]',
  id  = $_[0] . '_' . $_[2],
);
sleep 8;

}

When the code is executed, I get an error

 *Can't use string (some) as a SCALAR ref while strict refs *

This is resolved using - *no strict 'refs*';

Do we need to always use the above while using Perl variable indirection
- ${$_[0]}

Parag


Re: Inviting ideas for Personal database

2011-10-05 Thread Parag Kalra



 Finally, I should note that you shouldn't prefix your replies with PK or


Agreed. My mistake. Thanks for bringing it to my notice. BTW I have started
using sqllite and I am really enjoying it. Thanks to all.

Parag


Inviting ideas for Personal database

2011-10-04 Thread Parag Kalra
I am planning to write a small, non-bulky, easy to use and easy to port
application for my personal use.

There is lot of information I store on Google docs like commands, key words,
directory locations, script names etc. Pretty much everything which I use
daily.

Switching from shell to Web-browser is sometimes not so convenient.

Hence I am planning to store these information in flat files with some
keyword/switch and then use my application to parse and fetch the
information I am looking for.

Is there any better approach I can use instead of flat files like some
personal db etc. One of the concern I have with databases like MySQL etc is
that I would also have to install which would become a dependency and being
honest I also dont' have that huge of a data.

Does Perl have any standard database which comes installed with the standard
package ON ALL Operating Systems.

Feel free to share your thoughts.

TIA

Parag


Re: Inviting ideas for Personal database

2011-10-04 Thread Parag Kalra
On Tue, Oct 4, 2011 at 3:38 PM, Brandon McCaig bamcc...@gmail.com wrote:

 On Tue, Oct 4, 2011 at 5:41 PM, Shawn H Corey shawnhco...@gmail.com
 wrote:
  If the database is small, I would consider using SQLite. It stores the
  entire database in a single file which makes it easy to backup and
 transfer.
  Thunderbird and Firefox use it extensively.

 I second SQLite. :) It's basically perfect for a lightweight database.


PK Thank you all for pointing to SQLite. Other question I have is SQLite
and DBI part of standard Perl package or do I need to explicitly install the
modules.


 Though I question the types of information you have and what you
 do with it. If it's just like configuration and documentation to
 remind yourself of commands and APIs and such then I might
 suggest you instead just use shell scripts/config files and man
 pages or PODs and version it all with Git (possibly in different
 repos). :) You can create a public repository on one of the DVCS
 Web sites and make it available where ever you go. :) That way
 all of your stuff is only a clone away.

 For example, I try to keep all of my non-sensitive dotfiles in my
 'rc' repository: https://github.com/bamccaig/rc/


PK Yes I also keep my personal projects on Github, most likely would keep
this one as well.




 This way when I login to a new system for the first time I just
 clone my rc repo from GitHub and create symlinks and that fast I
 have all of my personal configuration setup. :)


 --
 Brandon McCaig bamcc...@gmail.com bamcc...@castopulence.org
 Castopulence Software https://www.castopulence.org/
 Blog http://www.bamccaig.com/
 perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
 q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
 tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'

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





Can't use string (1) as a HASH ref while strict refs

2011-09-19 Thread Parag Kalra
Hi,

I was getting this error message for one of my script.

The reason came out out to be, I had not place a semi-colon at the end of
try-catch block.

try {
   something
} catch some_exception {
  do something
}

After I placed the semi-colon, I am no longer getting this error (Can't use
string (1) as a HASH ref while strict refs)

try {
   something
} catch some_exception {
  do something
};

My questions is I have quite a few scripts that are using the SAME try-catch
block without a semi-colon but those are working seamlessly. They why was I
getting the error for only this try-catch block.

Is there some rule which we need to follow while using try-catch in Perl?

Thanks,
Parag


Good resources on CGI programming with Perl

2011-09-08 Thread Parag Kalra
Hi,

Could some please suggest any good online resources on learning CGI
programming with Perl

Also please let me know the goods for the same.

Thanks,
Parag

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




Re: please Perl help...

2011-09-04 Thread Parag Kalra
use strict;
use warnings;
while(DATA){
my $num = $. - 1;
s/\d+/$num/ if /\w+\s+\d+\s+\w/;
print $_;
}

__DATA__
charith 4 matara
saman 8 kandy
andrew 9 colombo
dilshan 3  galle
shanil 10 jafna


Parag

On Fri, Sep 2, 2011 at 8:42 PM, Charith LokuBogahawatta
charith...@gmail.com wrote:
 Hi All,

 I'm new to this group also for perl but nowadays I working around with
 Perl and I need some help. this my first thread please anyone can help
 me?

 i have a file contains the following data.

 charith 4 matara
 saman 8 kandy
 andrew 9 colombo
 dilshan 3  galle
 shanil 10 jafna
 .
 .
 .
 Here  I want to replace second column (Number) with incremental number
 sequence. output should be following.

 charith 0 matara
 saman 1 kandy
 andrew 2 colombo
 dilshan 3  galle
 shanil  4 jafna
 .
 .
 .

  Thank you very much


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




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




Re: how to do this in perl (from unix)

2011-09-01 Thread Parag Kalra
Please give a better problem statement like what is the form of data
initially present in the file and what you wish to extract.

You should also post sample file data for both the files (before and after)

Not all people who know Perl might know Unix commands (rare but
possible) and so they may not be able to construct the requirement.

Thanks,
Parag

On Thu, Sep 1, 2011 at 4:38 PM, Rajeev Prasad rp.ne...@yahoo.com wrote:
 from linux:

 cut -f1,5- -d  file |grep -v ^0 | sort -n  to_file;   ==this line: 
 how to achieve this in perl?


 will below work,  in perl?

 if ( ! -s $sourcedir/somefile ){

  open(tmpFH,,file2);
  @tmpAR = tmpFH;
  close(tmpFH);

  push(@tmpAR2,$tmpAR[0],$tmpAR[5..]);#select on columns 1 and 5 
 onwards from the original file

  my @tmpAR3 = grep {!^[0 ]} @tmpAR2; #omit line with 0 in the 
 beginning

  @tmpAR3 = sort(@tmpAR3);# sort on the first column
  }

 we can then print tmpAR3 to a file.


 plz. advice. thx.

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




Re: CPAN on Windows Box

2011-08-23 Thread Parag Kalra
Try this:

cpaninstall Tk

Parag

On Tue, Aug 23, 2011 at 3:04 PM, Emeka emekami...@gmail.com wrote:

 Hello All
 I tried this in order to install Perl-tk   cpaninstall tk... But it
 failed to work.

 Emeka
 --
 *Satajanus  Nig. Ltd


 *



Timeout for user input

2011-06-17 Thread Parag Kalra
Hi,

I have a requirement where I want to wait for user to input the data.

However if user doesn't input the data within certain period of time then it
should timeout and move ahead.

TIA

~Parag


Efficient way to compare 2 data structures particularly hash

2011-04-30 Thread Parag Kalra
Hi,

I am evaluating different approaches to compare data structures in Perl -
i.e whether they are same or not.

I am planning to start wit:

1. Data::Compare

2. And then found this -
http://stackoverflow.com/questions/1273616/how-do-i-compare-two-hashes-in-perl-without-using-datacompare

Any other options or suggestions?

I would like to use the most efficient.

~Parag


Auto-numbering in perlpod

2011-04-17 Thread Parag Kalra
Hi,

While creating POD for modules in Perl, I often specify numbered list

1. Parameter1
2. Parameter2
3. Parameter3
..
...
etc

or

1. It does this
2. It also does that
3. But it won't do this
...
..
etc

Currently the numbered list is hard-coded (i.e numbers 1, 2, 3 etc). Can I
make it auto-increament like

[some-tag Param1 close-tag]
[some-tag Param2 close-tag]
[some-tag Param3 close-tag]
etc

TIA

~Parag


Dynamic replacement of the variable

2011-04-17 Thread Parag Kalra
Hi,

I am not sure if this can be done. But just asking it out of curiosity. I
have written this snippet.

use strict;
use warnings;

my $var = '$str abc_xyz';
my $str;

for(my $i=1;$i = 5; $i++){
$str = $i;
my $line = 'Line: '.$var;
print $line\n;
}

Currently it displays:

Line: $str abc_xyz
Line: $str abc_xyz
Line: $str abc_xyz
Line: $str abc_xyz
Line: $str abc_xyz

But can I make it output following:

Line: 1 abc_xyz
Line: 2 abc_xyz
Line: 3 abc_xyz
Line: 4 abc_xyz
Line: 5 abc_xyz

i.e. I want $str to be dynamically replaced with the value of number.

~Parag


Locking NFS files using File::NFSLock

2011-04-12 Thread Parag Kalra
Hi,

I was just exploring File::NFSLock to lock files on the NFS server but seems
like its not working. It ends up creating stale files and only option left
is to abort the script. I am testing it on NFSv3

Anybody had any success in using this module?

Here is my sample code.

use strict;
use warnings;

use File::NFSLock qw(uncache);
use Fcntl qw(LOCK_EX LOCK_NB);
print Please enter the file to be locked:\n;
chomp(my $file = STDIN);
open my $fh, '', $file or die $!;
print $fh Hello World;
print Please try to write to the file\n;
my $wait = STDIN;
#my $lock = File::NFSLock-new($file,LOCK_EX|LOCK_NB,10*60,30*60);
my $lock = File::NFSLock-new($file,LOCK_EX,10*60,30*60);
print File is now locked. Now again try to write to the file\n;
$wait = STDIN;
print Lock operation over\n;

~Parag


Perl packet tracking module

2011-03-23 Thread Parag Kalra
Hi,

Does Perl have any packet tracking module equivalent to tcpdump, snoop,
tshark or tethereal

TIA

~Parag


Re: MRF-ERROR: Is a directory

2011-03-16 Thread Parag Kalra
On Wed, Mar 16, 2011 at 11:44 AM, ind...@students.itb.ac.id wrote:

 how to overcome this error :

 MRF-ERROR: Is a directory



Please post the entire code.

~Parag


Re: help with array elements

2011-03-12 Thread Parag Kalra


 could some one throw some light on how i can do this.
 thanks in advance..


use strict;
use warnings;

my @array = (1,2,3,4,2,3,1,2,1,1,1,4,6,7);
my %hash;
foreach my $item (@array){
if (exists $hash{$item}) {
$hash{$item} = $hash{$item} + 1;
} else {
$hash{$item} = 1;
}
}

print @array\n;
while(my ($key,$val) = each %hash) {
print $key = $val\n;
}

~Parag


Printing Bash and Kernel Version numbers using Perl

2011-03-12 Thread Parag Kalra
Hi,

Wanted to have suggestions to modify below 1 liner so that it can also print
Shell (preferably Bash) version and along with Operating System Kernel
version.

Currently I am just printing the place holders for Shell and Kernel version
numbers.

perl -MConfig -le 'print
$Config{perlpath}:$^V\n$ENV{SHELL}:Bash_or_Shell_Version\n/kernel/$^O:Kernel_Version'

TIA

~Parag


Re: Printing Bash and Kernel Version numbers using Perl

2011-03-12 Thread Parag Kalra
perl -MConfig -e 'print $Config{perlpath}:$^V\n$ENV{SHELL}: . qx{ bash
 --version | head -1 } . /kernel/$^O: . qx{ uname -r }'


Vern Nice. Completely impressed. But I thought Perl might have some internal
variable at least for Kernel version. But anyways this work for me too.

~Parag


Re: Testing File Contents

2011-03-02 Thread Parag Kalra
# Untested
use strict;
use warnings;

open my $fh, '', my_file;
while($fh){
if ($_ !~ /my_string/) {
# Do something
}
}

The other way would be on shell -

# Untested
grep my_string my_file
if [ $? -eq 1 ]
then
echo Do something
fi
~Parag



On Wed, Mar 2, 2011 at 9:55 AM, Matt lm7...@gmail.com wrote:

 I am looking for a simple way to test if a file does not contain a
 string.  This is on a linux box.

 if myfile does not contain mystring {
  #do_something;
  }

 The file is basically a list of names and I want to test that a
 certain name is not in there.  Is there an easy way to do that?

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





Re: Testing File Contents

2011-03-02 Thread Parag Kalra
On Wed, Mar 2, 2011 at 10:11 AM, Parag Kalra paragka...@gmail.com wrote:

Sorry for the top post. I should have done bottom post. :(

# Untested
 use strict;
 use warnings;

 open my $fh, '', my_file;
 while($fh){
 if ($_ !~ /my_string/) {
 # Do something
 }
 }

 The other way would be on shell -

 # Untested
 grep my_string my_file
 if [ $? -eq 1 ]
 then
 echo Do something
 fi
 ~Parag





 On Wed, Mar 2, 2011 at 9:55 AM, Matt lm7...@gmail.com wrote:

 I am looking for a simple way to test if a file does not contain a
 string.  This is on a linux box.

 if myfile does not contain mystring {
  #do_something;
  }

 The file is basically a list of names and I want to test that a
 certain name is not in there.  Is there an easy way to do that?

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






How does the function loading works in Perl

2011-03-02 Thread Parag Kalra
Hi,

I have this basic question from a long time now, so thought of asking.

A Perl script may have many functions. When we execute the script via Perl
Interpreter, does all the functions are loaded into memory?

Sometimes we just like to keep the coded functions in the script with the
idea that we may need them in future. Will removing an un-called functions
improve the execution time?

~Parag


Re: string substitution command question

2011-02-26 Thread Parag Kalra
use strict;
use warnings;
while(DATA){
chomp;
if ($_ =~ /NM_(\d+)/){
my $found = $1;
$_ =~ s/$found/$found:12345/g;
print $_\n;
} else {
print $_\n;
}
}

__DATA__
chr1ucscexon226488874   226488906   0.00
-   .   gene_id NM_173083; transcript_id NM_173083;
chr1ucscexon226496810   226497198   0.00
-   .   gene_id NM_173083; transcript_id NM_173083;
chr1ucscexon2005086 2005368 0.00+   .
gene_id NM_001033581; transcript_id NM_001033581;
chr1ucscexon2066701 2066786 0.00+   .
gene_id NM_001033581; transcript_id NM_001033581;

~Parag



On Sat, Feb 26, 2011 at 12:06 PM, Richard Green gree...@uw.edu wrote:

 Hi Perl users, Quick question, I have a one long string with tab delimited
 values separated by a newline character (in rows)
 Here is a snippet of the the string:

 chr1ucscexon226488874   226488906   0.00
 -   .   gene_id NM_173083; transcript_id NM_173083;
 chr1ucscexon226496810   226497198   0.00
 -   .   gene_id NM_173083; transcript_id NM_173083;
 chr1ucscexon2005086 2005368 0.00+   .
 gene_id NM_001033581; transcript_id NM_001033581;
 chr1ucscexon2066701 2066786 0.00+   .
 gene_id NM_001033581; transcript_id NM_001033581;

 I am trying to perform substitution on some values at the end of each rows,
 for example, I'm trying to replace the above string with the following:

 chr1ucscexon226488874   226488906   0.00
 -   .   gene_id NM_173083:12345; transcript_id NM_173083:12345;
 chr1ucscexon226496810   226497198   0.00
 -   .   gene_id NM_173083:12345; transcript_id NM_173083:12345;
 chr1ucscexon2005086 2005368 0.00+   .
 gene_id NM_001033581:12346; transcript_id NM_001033581:12346;
 chr1ucscexon2066701 2066786 0.00+   .
 gene_id NM_001033581:12346; transcript_id NM_001033581:12346;

 Here is the substitution command I am trying to use:

 $data_string=~ s/$gene_id\NM_173083\\; transcript_id
 \NM_173083\\;/\NM_173083:12345\\; \NM_173083:12345\\;/g;

 $data_string=~ s/$gene_id\NM_001033581\\; transcript_id
 \NM_001033581\\;/\NM_001033581:12346\\; \NM_001033581:12346\\;/g;

 I don't know why I am not able to substitute at the end of each row in the
 string.
 Any suggestions folks have are muchly appreciated. Thanks -Rich



Re: string substitution command question

2011-02-26 Thread Parag Kalra
On Sat, Feb 26, 2011 at 12:34 PM, Uri Guttman u...@stemsystems.com wrote:

  PK == Parag Kalra paragka...@gmail.com writes:

  PK use strict;
  PK use warnings;
  PK while(DATA){
  PK chomp;

 why are you chomping here when you add in the \n later?


 Agreed and corrected in the example at the bottom.


  PK if ($_ =~ /NM_(\d+)/){
  PK my $found = $1;
  PK $_ =~ s/$found/$found:12345/g;

 many issues there. why do you test the match before making the s///? you
 can ALWAYS do an s/// as it will just fail if it doesn't match.


 Rectified in the example at the bottom.



 why are you doing s/// against $_? by default it does that.

  PK print $_\n;
  PK } else {
  PK print $_\n;
  PK }

 why are you printing the same thing in each clause? just print AFTER the
 change is made?


Big mistake. I accept it. Modified in the example at the bottom.




 why do you top post when you have been told to bottom post and edit the
 quoted email?


Sorry. Hope this reply is better and so as the following code:

use strict;
use warnings;
while(DATA){
$_ =~ s/NM_(\d+)/$1:12345/g;
print;
}

__DATA__
chr1ucscexon226488874   226488906   0.00
-   .   gene_id NM_173083; transcript_id NM_173083;
chr1ucscexon226496810   226497198   0.00
-   .   gene_id NM_173083; transcript_id NM_173083;
chr1ucscexon2005086 2005368 0.00+   .
gene_id NM_001033581; transcript_id NM_001033581;
chr1ucscexon2066701 2066786 0.00+   .
gene_id NM_001033581; transcript_id NM_001033581;




 uri



Thanks for the review

~Parag



 --
 Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com--
 -  Perl Code Review , Architecture, Development, Training, Support
 --
 -  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com-



Re: string substitution command question

2011-02-26 Thread Parag Kalra
On Sat, Feb 26, 2011 at 12:56 PM, Uri Guttman u...@stemsystems.com wrote:

  PK == Parag Kalra paragka...@gmail.com writes:

why are you doing s/// against $_? by default it does that.

 you didn't rectify this one.


Oops. Missed that.




  PK Sorry. Hope this reply is better and so as the following code:

 much better.


Thanks.



  PK use strict;
  PK use warnings;
  PK while(DATA){
   PK $_ =~ s/NM_(\d+)/$1:12345/g;

 i didn't follow the request carefully. that is dropping the NM_ part.


Good catch.

use strict;
use warnings;
while(DATA){
s/NM_(\d+)/NM_$1:12345/g;
print;
}

__DATA__
chr1ucscexon226488874   226488906   0.00
-   .   gene_id NM_173083; transcript_id NM_173083;
chr1ucscexon226496810   226497198   0.00
-   .   gene_id NM_173083; transcript_id NM_173083;
chr1ucscexon2005086 2005368 0.00+   .
gene_id NM_001033581; transcript_id NM_001033581;
chr1ucscexon2066701 2066786 0.00+   .
gene_id NM_001033581; transcript_id NM_001033581;




 uri


Thanks once again.

~Parag


  --
 Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com--
 -  Perl Code Review , Architecture, Development, Training, Support
 --
 -  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com-



Re: auto login to remote server using Net::SSH::Expect

2011-02-23 Thread Parag Kalra
1. What error message do you get
2. Could you try the script with strict and warnings.
3. Could you also use die and $!
4. Did you check sshd logs on the server

~Parag



On Tue, Feb 22, 2011 at 11:51 PM, Agnello George
agnello.dso...@gmail.comwrote:

 Hi

 i am able to run  a command on the remote machine but i am not able to
 completely login to the remote machine

 =
 use Net::SSH::Expect;

 my $ssh = Net::SSH::Expect-new (
  host = 1.1.1.1 ,
  password= password,
  user = user1,
  raw_pty = 1
  );

 myl $login_output = $ssh-login();
 print This is the login promt $login_output;
 print \n;


 ==

 thanks for all the help

 --
 Regards
 Agnello D'souza



Re: Access single element of AOH

2011-02-21 Thread Parag Kalra
print $object-[$stp]-{'lieferung'},\n;

~Parag



On Mon, Feb 21, 2011 at 12:46 AM, HACKER Nora nora.hac...@stgkk.at wrote:

 Hello,

 I want to get the value of a key of a Hash that is part of an Array of
 Hashes, whereas the correct hash to work with is being determined by the
 value of another key which is passed as an argument when calling the
 script, but haven't yet figured out how. This is my AOH:

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

 my $stp = $ARGV[0];

 my $object = [
{   'stp'   = 'AV'
  , 'lieferung' = 'D:\mvbwiega\stp_be\LIEFERUNG'
  , 'hvb'   = 'H:\stp-be\LIEFERUNG'
  , 'tux'   = 'Releaseschein-2004\Server\Tuxedo'
  , 'ubbconfig' = 'beispiel_ubbconfig.txt'
},
{   'stp'   = 'BE'
  , 'lieferung' = 'D:\mvbwiega\stp_be\LIEFERUNG'
  , 'hvb'   = 'H:\stp-be\LIEFERUNG'
  , 'tux'   = 'Releaseschein-2004\Server\Tuxedo'
  , 'ubbconfig' = 'beispiel_ubbconfig.txt'
},
{   'stp'   = 'PKV'
  , 'lieferung' = 'D:\mvbwiega\stp_pkv\Releases'
  , 'hvb'   = 'H:\stp-pkv\Releases'
  , 'tux'   = 'RS_2004\Tuxedo'
  , 'ubbconfig' = 'beispiel_ubbconfig.txt'
}
 ];

 And these were (some of) my failing attempts:

 print $object{'lieferung'}{$stp}\n;
 == Global symbol %object requires explicit package name at
 ./test.pl line 71.
 == Execution of ./test.pl aborted due to compilation errors.

 print $object-[$stp]{'lieferung'}\n;
 == Argument AV isn't numeric in array element at ./test.pl line
 72.
 == D:\mvbwiega\stp_be\LIEFERUNG# always result of first hash,
 no matter which parameter given

 print $object-{$stp}{'lieferung'}\n;
 == Pseudo-hashes are deprecated at ./test.pl line 72.
 == No such pseudo-hash field AV at ./test.pl line 72.

 Somehow I only seem to find examples/explanations with 'foreach'es,
 looping over the whole AOH ... Is it even possible what I want to
 realize? Or do I have to change my data structure to a Hash of Hashes,
 would that be better/easier?

 Thanks in advance,
 Nora






Re: Assistance with regular expression

2011-02-14 Thread Parag Kalra
What you should probably do is to use hashes.

Something like this:

1. Read the first file.
2. Split the each item of first file using an hyphen
3. Store the first item as the keys of hash say - file1_hash
4. Read the second file and store the items as the keys of a new hash say -
file2_hash
5. Loop through the file1_hash and determine the keys that are not present
in - file2_hash

~Parag



On Mon, Feb 14, 2011 at 4:09 PM, William Muriithi 
william.murii...@epicadvertising.com wrote:

 Pal,

 I have to files that I am trying to match:

 Generated from rpm -qa  file1
 file1
 libstdc++-4.1.2-48.el5
 info-4.8-14.el5
 libICE-1.0.1-2.1
 libacl-2.2.39-6.el5
 lcms-1.18-0.1.beta1.el5_3.2
 dmidecode-2.10-3.el5
 ...

 Generate from rpm -qa --queryformat '%{NAME}\n'  file2
 file2
 acl
 alacarte
 alchemist
 alsa-lib
 alsa-utils
 amtu
 apr
 apr-util
 aspell
 aspell-en
 ..

 I am trying to list files that exist on file1 that are missing on file2 and
 have the following script:

 #! /usr/bin/perl

 use strict;
 #use warning;

 open MSRT, /Users/williamm/Documents/file1 or die $!;
 open Test_server, /Users/williamm/Documents/file2 or die $1;
 #open MSRT, /Users/williamm/test1_rpm.txt or die $1;
 #open Test_server, /Users/williamm/test2_rpm.txt or die $1;

 my $tom;
 my $msrt;

 while   ($tom = Test_server) {
  chomp($tom);
 #  print T:$tom\n;
  while ($msrt = MSRT) {
chomp($msrt);
 #print M:$msrt\n;
 if ($msrt =~ /^\Q$tom\E/){
 #if ($msrt =~ m/^$tom.*$/){
  print $tom: $msrt\n;
 #  print Found\n;
}
  }
 }


 williamcomputer:~ williamm$ perl compareRPM.pl
 acl-2.2.39-6.el5: acl-2.2.39-6.el5

 It does loop through the two files fine, but I think the regular expression
 is not working fine.  It only match one RPM, but I have been able to find
 many others that should have matched. For example, this should have been
 printed out.

 krb5-libs-1.6.1-36.el5_4.1:  krb5-libs

 Any idea of what tweak to the regular expression I need apply to make it
 work properly?  Also, advice of a better way of solving this problem would
 also be appreciated.

 Thanks in advance

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





Re: about return

2011-02-09 Thread Parag Kalra
Is this what you mean

($exist) ? return 1 : return undef

I think even this should work

($exist) ? 1 : 0;

~Parag



2011/2/9 terry peng terry.p...@mail.ru


 hello,

 when in the case return undef I prefer just return coz in list context
 it will return an empty list.

 my $exist = ...
 if ($exist) {
return 1;
 } else {
return;
 }

 the code above can work, but having many lines.
 So I want:

 return $exist ? 1 : (...);

 what should be put in (...) to get the same effect as just return (not
 return undef)?

 regards.



Re: reference noob

2011-02-03 Thread Parag Kalra
 print $field\n

~Parag



2011/2/3 Téssio Fechine precheca...@yahoo.com.br

 The program:
 --
 #use strict;
 use warnings;

 my $field = shift @ARGV;
 my $regex = '(\w+)\s*' x $field;

 while (STDIN) {
if (/$regex/) {
print $$field\n;  # refers to a match variable
}
 }
 --

 Example Usage:
 --
 $ echo 'Strange New World!' | ./this_program 3
 $ World
 --

 How could I do this with 'use strict' turned on?




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





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

2011-01-27 Thread Parag Kalra
When you are already storing the line under $line
while(( my $line = FILEHANDLE)) {

Then why are you using $_
my @fields = split '\|', $_;

Cheers,
Parag



On Thu, Jan 27, 2011 at 12:57 PM, CM Analyst cmanal...@yahoo.com wrote:

 Hello,

 In the following script my goal is pull the date value each time an error
 value (hardcoded) is found in the specified log file. The script retrieves
 the error value without a problem but I cannot seem get the date value. Can
 anyone tell me what I need to do?

 The error message when I run the script is:

 Use of uninitialized value in concatenation (.) or string at script.plline 32

 where line 32 is where I am calling this:

 print $date;

 Here is the script:

 use warnings;
 use strict;

 #Specify the path to the log file you want to read, for ex. application
 log#

 open (FILEHANDLE, 'd:/scripts/server2.log') or print Can't Open File!!!;

 while(( my $line = FILEHANDLE)) {

 #Searching for keywords from application log#

 if (($line =~ m/CQCommitException/i ) || ($line =~ m/Communication link
 failure/i)) {

 my @fields = split '\|', $_;
 my $date   = $fields[1];

 print $date;

 #prints $line to file
 open (my $outfile, , d:/scripts/loginfo.txt) or die Can't open
 loginfo.txt: $!;

 print $outfile $date, $_\n;

 #close $outfile or die $outfile:$!;

}
 }

 my $outfile = 'd:/scripts/loginfo.txt';

 #To send or not to send - file size check

 #Delete file when done
 #unlink 'd:\scripts\loginfo.txt';

 -END-




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





Re: Need help in Expect Module

2011-01-19 Thread Parag Kalra
Snippet of what I understand from your requirement:

parag@ubuntu-studio:~$ cat app
#!/bin/bash
if [ $# -ne 1 ]
then
echo -e Invalid number of input\nUsage: app input
exit 1
else
input=$1
fi

if [ $input != register ]
then
echo Invalid choice
exit 1
fi

echo mac
echo windoze
echo Select the server to register:
echo -n ubuntu(default):
read os

case $os in

mac)
echo rich spoiled brat
;;
windoze)
echo old arrogant user
;;
ubuntu)
echo smart sexy nerd
;;
*)
echo invalid choice
;;
esac
parag@ubuntu-studio:~$

parag@ubuntu-studio:~$ cat expect.pl
use strict;
use warnings;
use Expect;

my $app = ./app register;
my @oss = qw/ubuntu mac windoze/;
my $choice = $oss[rand @oss];

my $exp = new Expect;
$exp-spawn($app) or die $!\n;
$exp-expect(15,[
  qr/default/ =
   sub {
   my $ch = shift;
   print $ch $choice\n;
   exp_continue;
}
 ]
  );

parag@ubuntu-studio:~$

Is this what you want?

~Parag


On Mon, Jan 17, 2011 at 10:19 PM, Zaheer zaheer...@gmail.com wrote:
 Hi,
 I am trying to automate a cli application that has multiline output. I
 want to be able to grep for this multi line output as single string
 using Expect module and send some keys as input.

 The cli would be something like

 bash-3.00# /opt/myapp/bin/app register

 1) someservername(1)
 2) someoptionalserver(2)
 Select destination server or enter full URL for alternate server
 [somedefaultserver(3)]:

 How can I do this using Expect?

 Thanks in advance..


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




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




Return value from function

2011-01-12 Thread Parag Kalra
Hi,

On shell, successful command returns exit status of 0.

As a best practice what status value shall a Perl function return.

Going by the fact that Perl function returns the value of last command
in it, I think function should return non-zero for a success.

Cheers,
Parag

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




Re: Getting LineFeed for Excel within q quoted field

2011-01-06 Thread Parag Kalra
        So how do I telSo how do I tell Perl to leave alone on 0a. Do 
 I have to play with $? Or ???
Making no sense to me at this point...l Perl to leave alone on 0a. Do 
 I have to play with $? Or ???
        Making no sense to me at this point...


use strict;
use warnings;
open my $fh, '', 'file.out' or die Could not create file: $!\n;
binmode($fh);
print $fh New\nLine;

This would insert 0a where you have used \n irrespective of Operating System.

And if you want to generate 0d0a for \n specially on Unix then modify
the fourth line of the above script to binmode($fh,':crlf')

Cheers,
Parag




On Wed, Jan 5, 2011 at 3:48 PM, Wagner, David --- Senior Programmer
Analyst --- CFS david.wag...@fedex.com wrote:
 Original Message-
From: Parag Kalra [mailto:paragka...@gmail.com]
Sent: Wednesday, January 05, 2011 16:42
To: Wagner, David --- Senior Programmer Analyst --- CFS
Cc: Perl Beginners
Subject: Re: Getting LineFeed for Excel within q quoted field

Ok.

May be I need to understand your scenario in better way. Kindly
correct me if I am wrong. So this is what my understanding is:

1. Your aim is to generate a CSV file
2. You are parsing a flat text file and substituting ^ with new line
character (0a)
3. But when you are viewing the file in Excel the new character is not
added
 [Wags] Not quite. I look at the file using Hex application. What I see in the 
 file is
 0d0a where I would expect to ONLY see 0a. As another test, I changed the 0a 
 to 0f and
 Ran my script. When I look at the file, it ONLY has the 0f. So what I am 
 thinking is
 That Perl sees the 0a and says he is not doing it right, so we will replace 
 with a
 0d0a since on Windows. Simplistic, but that is what I am seeing.

        So how do I tell Perl to leave alone on 0a. Do I have to play with $? 
 Or ???
        Making no sense to me at this point...

        So what are the thoughts now???

  If you have any questions and/or problems, please let me know.
  Thanks.

 Wags ;)
 David R. Wagner
 Senior Programmer Analyst
 FedEx Services
 1.719.484.2097 Tel
 1.719.484.2419 Fax
 1.408.623.5963 Cell
 http://Fedex.com/us

4. And reason as per what you think is that Excel is expecting 0a but
what is getting inserted is 0d0a
5. Also I assume you are doing all these experiments on Windows box.
The reason I am asking this is because both Linux and Windows treat
new line character in different way. Have a look -
http://www.perlmonks.org/index.pl?node_id=68687
And from the same reference it appears to me that if you want to add
only 0a, may be you need to handle the csv file in ascii format

Cheers,
Parag




On Wed, Jan 5, 2011 at 3:28 PM, Wagner, David --- Senior Programmer
Analyst --- CFS david.wag...@fedex.com wrote:

-Original Message-
From: Parag Kalra [mailto:paragka...@gmail.com]
Sent: Wednesday, January 05, 2011 12:13
To: Wagner, David --- Senior Programmer Analyst --- CFS
Cc: Perl Beginners
Subject: Re: Getting LineFeed for Excel within q quoted field

It may have to do something how you are opening the file handler of CSV
file.

The data you seen in the csv file may depend on which encoding you
have used while creating the file.

Couple of questions:

1. I believe currently you are view the file on Windoze, when you view
the file on Unix, do you still see the graphics.

 [Wags] I am viewing with Scite and also a Hex editor.
 But even when I am doing the change using s/\^/\x0a/g I am seeing in the
file itself as 0d0a and not just the 0a. Obviously I am missing something
very basic at this point. Excel is expecting a 0a indicating a soft return,
and I have verified I am using the right code, but comes out incorrectly.

        What am I missing??

        Thanks much for any insight..

 Wags ;)
 David R. Wagner
 Senior Programmer Analyst
 FedEx Services
 1.719.484.2097 Tel
 1.719.484.2419 Fax
 1.408.623.5963 Cell
 http://Fedex.com/us



2. Is graphics visible on most of the editors or have you used only 1
editor?

Cheers,
Parag




On Tue, Jan 4, 2011 at 3:56 PM, Wagner, David --- Senior Programmer
Analyst --- CFS david.wag...@fedex.com wrote:
        I am generating an CSV and want a couple of fields to have soft
 returns in them. I went into Excel and added a couple of soft returns
to
 a couple of different fields and then saved the modified file back to a
 CSV.
        I opened in a editor and reviewed what was there. What I saw
 was:
 xxx(lf)         # shows as LF verses the std end of line for
 windows of CR/LF
 Yyyy(lf)
 

        I left the editor and double clicked again and brought into
 Excel. The data had the soft returns.

        So I added the following to my processing:

            for ( @MyWorka ) {
                if ( /\^/ ) {
                    s/\^/\x0a/g;        # I have tried the \r and even
 \n and when opened in
                                                # Excel always has the
 graphic explained below

Function to print Object properties

2011-01-06 Thread Parag Kalra
Hi,

This question is related to OOPs in Perl and I am learning and
enjoying it gradually.

Anyways I want to know is there any function or a way that would
reveal all the properties of the object.

For example if I have a package say Foo::Bar. Now assume that there is
a object called $fob and pretend that I don't know that its an
instance of Foo::Bar

There are many occasions while reviewing someone else's code that I
want to know the object properties like (Package to which it belongs,
sub routines I can execute using it etc)

So I am looking for some function that can print that.

Following is a snippet of my hypothetical idea.

EG:
use strict;
use warnings;
use Data::Dumper;
use Foo::Bar;
my $fob = Foo::Bar-new(); #pretend that I don't know this
my %obj_prop = some_function($fob)
print Dumper(%obj_prop); # This should print all the details of the function

Cheers,
Parag

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




Re: Function to print Object properties

2011-01-06 Thread Parag Kalra
Thanks it worked. :)

Cheers,
Parag



On Thu, Jan 6, 2011 at 6:31 PM, Shawn H Corey shawnhco...@gmail.com wrote:
 On 11-01-06 09:25 PM, Parag Kalra wrote:

 For example if I have a package say Foo::Bar. Now assume that there is
 a object called $fob and pretend that I don't know that its an
 instance of Foo::Bar

 print ref( $fob ), \n;

 See `perldoc -f ref`.


 --
 Just my 0.0002 million dollars worth,
  Shawn

 Confusion is the first step of understanding.

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

 The secret to great software:  Fail early  often.

 Eliminate software piracy:  use only FLOSS.

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




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




Re: Function to print Object properties

2011-01-06 Thread Parag Kalra
Awesome.

Thanks Alan and Shawn

Cheers,
Parag




On Thu, Jan 6, 2011 at 6:52 PM, Alan Haggai Alavi
alanhag...@alanhaggai.org wrote:
 Hi Parag,

 On Friday 07 January 2011 07:55:38 Parag Kalra wrote:
 Anyways I want to know is there any function or a way that would
 reveal all the properties of the object.

 Introspect the symbol table hash (stash):

 use strict;
 use warnings;

 use Data::Dumper;
 use Foo::Bar;

 my $fob = Foo::Bar-new();
 my $package = ref $fob;

 {
    no strict 'refs';
    print Dumper \%{${package}::};
 }

 Regards,
 Alan Haggai Alavi.
 --
 The difference makes the difference.


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




Re: Out of memory, HTML::TableExtract

2011-01-06 Thread Parag Kalra
 Maybe because you aren't closing each file after you have done your thing
 and it remains in memory?

Well I may be wrong but I think since he is using same file handler
for each file, new instance is over writing the older one so all files
cannot remain opened and hence cannot be in memory.

I think here the issue is that the array is saturating the memory. May
be he needs to write the data to some temp file and flush the array
for each file.

Cheers,
Parag




On Thu, Jan 6, 2011 at 6:59 PM, Robert sigz...@gmail.com wrote:
 Maybe because you aren't closing each file after you have done your thing
 and it remains in memory?

 On 2011-01-06 02:26:13 -0500, Jins Thomas said:

 --0016364270585953cf049927ffd4

 Content-Type: text/plain; charset=ISO-8859-1



 Hi experts,



 Have you ever experienced Out of memory problem while using

 HTML::TableExtract. I'm having little large html files, still i didn't

 expect this to happen



 Would you be able to suggest some workarounds for this. I'm using this

 subroutine in another for loop.



 sub zParseHTMLFiles ($$) {



    my ( $lrefFileList, $lrefColNames ) = @_;

    my @ldata;

    foreach my $lFile (@$lrefFileList) {

        my $lTableExtract = HTML::TableExtract-new( headers =

 [...@$lrefcolnames] );

        chomp($lFile);

        $lTableExtract-parse_file($lFile);

        foreach my $ls ( $lTableExtract-tables ) {

            foreach my $lrow ( $lTableExtract-rows ) {

                chomp( @$lrow[$#$lrow] );

                push( @ldata, $lrow );

            }

        }

    }

    return \...@ldata;

 }



 Thanks

 Jins Thomas



 --0016364270585953cf049927ffd4--





 --
 Robert



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




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




Re: Getting LineFeed for Excel within q quoted field

2011-01-05 Thread Parag Kalra
It may have to do something how you are opening the file handler of CSV file.

The data you seen in the csv file may depend on which encoding you
have used while creating the file.

Couple of questions:

1. I believe currently you are view the file on Windoze, when you view
the file on Unix, do you still see the graphics.
2. Is graphics visible on most of the editors or have you used only 1 editor?

Cheers,
Parag




On Tue, Jan 4, 2011 at 3:56 PM, Wagner, David --- Senior Programmer
Analyst --- CFS david.wag...@fedex.com wrote:
        I am generating an CSV and want a couple of fields to have soft
 returns in them. I went into Excel and added a couple of soft returns to
 a couple of different fields and then saved the modified file back to a
 CSV.
        I opened in a editor and reviewed what was there. What I saw
 was:
 xxx(lf)         # shows as LF verses the std end of line for
 windows of CR/LF
 Yyyy(lf)
 

        I left the editor and double clicked again and brought into
 Excel. The data had the soft returns.

        So I added the following to my processing:

            for ( @MyWorka ) {
                if ( /\^/ ) {
                    s/\^/\x0a/g;        # I have tried the \r and even
 \n and when opened in
                                                # Excel always has the
 graphic explained below
                 }
             }

        Whereever there is a ^ replace with a hex A which to me is a
 LineFeed ( incorrectly as I have read ). I run and create my csv. I
 double click the file and it opens in Excel. It appears to be working,
 but where each linefeed is you get a little graphic with a question mark
 inside a circle. In a way it is doing the soft returns, but obviously
 not correctly.

        Any thoughts on what I am doing incorrectly??

         Thanks.

 Wags ;)
 David R. Wagner
 Senior Programmer Analyst
 FedEx Services
 1.719.484.2097 Tel
 1.719.484.2419 Fax
 1.408.623.5963 Cell
 http://Fedex.com/us



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




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




Re: automation frameworks

2011-01-05 Thread Parag Kalra
For what kind of testing are you looking frameworks?

Frameworks may differ for Database testing, Protocol testing, Storage
Testing etc

I believe putting arch or functional spec of any framework in one
email would be tough for anyone and also not sure if anyone would
share that because of compliance issues.

May be you can share the framework which you have in mind or one which
you are using (provided your employer allows you to share that) and we
may visit that and share our comments and suggestions.

Cheers,
Parag




On Wed, Jan 5, 2011 at 5:44 AM, Sunita Rani Pradhan
sunita.prad...@altair.com wrote:
 Hi All



 Could you please let me know , if anybody using any automation framework
 for their automation testing or any types information about automation
 framework ?



 Note: Perl scripting should be used in that framework .



 Thanks

 Sunita



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




Re: Getting LineFeed for Excel within q quoted field

2011-01-05 Thread Parag Kalra
Ok.

May be I need to understand your scenario in better way. Kindly
correct me if I am wrong. So this is what my understanding is:

1. Your aim is to generate a CSV file
2. You are parsing a flat text file and substituting ^ with new line
character (0a)
3. But when you are viewing the file in Excel the new character is not added
4. And reason as per what you think is that Excel is expecting 0a but
what is getting inserted is 0d0a
5. Also I assume you are doing all these experiments on Windows box.
The reason I am asking this is because both Linux and Windows treat
new line character in different way. Have a look -
http://www.perlmonks.org/index.pl?node_id=68687
And from the same reference it appears to me that if you want to add
only 0a, may be you need to handle the csv file in ascii format

Cheers,
Parag




On Wed, Jan 5, 2011 at 3:28 PM, Wagner, David --- Senior Programmer
Analyst --- CFS david.wag...@fedex.com wrote:

-Original Message-
From: Parag Kalra [mailto:paragka...@gmail.com]
Sent: Wednesday, January 05, 2011 12:13
To: Wagner, David --- Senior Programmer Analyst --- CFS
Cc: Perl Beginners
Subject: Re: Getting LineFeed for Excel within q quoted field

It may have to do something how you are opening the file handler of CSV
file.

The data you seen in the csv file may depend on which encoding you
have used while creating the file.

Couple of questions:

1. I believe currently you are view the file on Windoze, when you view
the file on Unix, do you still see the graphics.

 [Wags] I am viewing with Scite and also a Hex editor.
 But even when I am doing the change using s/\^/\x0a/g I am seeing in the file 
 itself as 0d0a and not just the 0a. Obviously I am missing something very 
 basic at this point. Excel is expecting a 0a indicating a soft return, and I 
 have verified I am using the right code, but comes out incorrectly.

        What am I missing??

        Thanks much for any insight..

 Wags ;)
 David R. Wagner
 Senior Programmer Analyst
 FedEx Services
 1.719.484.2097 Tel
 1.719.484.2419 Fax
 1.408.623.5963 Cell
 http://Fedex.com/us



2. Is graphics visible on most of the editors or have you used only 1
editor?

Cheers,
Parag




On Tue, Jan 4, 2011 at 3:56 PM, Wagner, David --- Senior Programmer
Analyst --- CFS david.wag...@fedex.com wrote:
        I am generating an CSV and want a couple of fields to have soft
 returns in them. I went into Excel and added a couple of soft returns to
 a couple of different fields and then saved the modified file back to a
 CSV.
        I opened in a editor and reviewed what was there. What I saw
 was:
 xxx(lf)         # shows as LF verses the std end of line for
 windows of CR/LF
 Yyyy(lf)
 

        I left the editor and double clicked again and brought into
 Excel. The data had the soft returns.

        So I added the following to my processing:

            for ( @MyWorka ) {
                if ( /\^/ ) {
                    s/\^/\x0a/g;        # I have tried the \r and even
 \n and when opened in
                                                # Excel always has the
 graphic explained below
                 }
             }

        Whereever there is a ^ replace with a hex A which to me is a
 LineFeed ( incorrectly as I have read ). I run and create my csv. I
 double click the file and it opens in Excel. It appears to be working,
 but where each linefeed is you get a little graphic with a question mark
 inside a circle. In a way it is doing the soft returns, but obviously
 not correctly.

        Any thoughts on what I am doing incorrectly??

         Thanks.

 Wags ;)
 David R. Wagner
 Senior Programmer Analyst
 FedEx Services
 1.719.484.2097 Tel
 1.719.484.2419 Fax
 1.408.623.5963 Cell
 http://Fedex.com/us



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





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




Re: perl training material and excercises for freshers

2011-01-03 Thread Parag Kalra
For beginners and exercises I would always recommend Learning Perl (
http://oreilly.com/catalog/9780596001322 )

The good thing about the book for trainers is that it gives you an
approximation each topic would take to teach and the time required to
complete the exercises.

You can also purchase its solutions book.

I don't know how much time you have to prepare for the training, but
my suggestion to you would be to prepare a PPT from this book and ask
your students to refer this book so that they can come prepared one
day before the topic.

You can then share the PPT with us as well. :)

Cheers,
Parag




On Sun, Jan 2, 2011 at 11:56 PM, Sunita Rani Pradhan
sunita.prad...@altair.com wrote:
 Hi All



            I am planning to give Perl training to my juniors in my
 team. They are new to Perl. Could anyone please send me any Perl
 training materials with exercises, or links, which I can refer to?

 Please send me good suggestions also for training.



 Thanks  Regards

 Sunita



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




Re: 1st line of perl script

2011-01-03 Thread Parag Kalra
Thats called Sha-Bang header also called Magical Bytes.

They come into picture when you do not specify the interpreter while
executing the script.

EG: ./my_script.pl (here no interpreter is specified i.e perl is missing)

In this case, script uses the interpreter specified at sha-bang header.

And now since you are specifying the interpreter on the prompt (perl
my_script.pl) hence its not showing any error even on windows.

Cheers,
Parag




On Mon, Jan 3, 2011 at 9:33 PM, Sunita Rani Pradhan
sunita.prad...@altair.com wrote:
 Hi All



            Perl script  works without the first line ( perl Interpreter
 : #! /usr/bin/perl) . What is the real use of this line ? This line does
 not through any error on Windows where , this path does not exist .

 Why is it so ?



 Could anybody explain it  clearly?



 Thanks

 Sunita



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




Re: advangtes of Perl on various languages

2011-01-03 Thread Parag Kalra
 - What all advantages Perl has on top of other scripting languages like
 Python , shell , Java ?

Its a never ending argument but the best advantage of Perl (according
to me) is light weight, very fast, Open Source, CPAN modules,
excellent documentation, small and easy way to do complex thing and
community support like this mailing list :). And the best thing which
I like about Perl compared to Java is you don't have to compile and
then run the byte code. I just hate that in Java (sorry to say that).
:(

 - What is the career growth, road map in Perl programming ?

Its very good and Perl is in great demand. Perl is being used in most
of the Server side and database testing and in most Automation and
administration tasks. To name few, its being used by top most
companies like Akamai and NetApp (and the list is very long). I would
always recommend to learn Perl to any beginner.

 I am not sure , if this questions are right for this group mail or not ,
 just asked . If it is not , please let me know which group can answer
 these .

I believe its a valid question and you have posted on the correct forum.


Cheers,
Parag




On Mon, Jan 3, 2011 at 11:12 PM, Sunita Rani Pradhan
sunita.prad...@altair.com wrote:
 Hi All



            I would like to know answers of following questions  :



 - What all advantages Perl has on top of other scripting languages like
 Python , shell , Java ?



 - What is the career growth, road map in Perl programming ?



 I am not sure , if this questions are right for this group mail or not ,
 just asked . If it is not , please let me know which group can answer
 these .





 Thanks

 Sunita







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




Re: Increment Operators

2011-01-02 Thread Parag Kalra
That means: $a = $a * 2

i.e take the existing value of $a, multiply it with 2 and reassign it to $a

Cheers,
Parag




On Sun, Jan 2, 2011 at 4:00 PM, J. S. John phillyj...@gmail.com wrote:
 Hi all, I'm new to Perl. The only other language I know is
 Matlab/Octave and I'm still working my way around Linux. I am using
 Shlomi Fish's tutorial on perl until I get the llama book. I'm stuck
 on section [4.1. += and friends ] [1]. I don't really understand the
 part $a *= 2; $b += 1; What is the *= mean?

 [1] 
 http://www.shlomifish.org/lecture/Perl/Newbies/lecture1/variables/plus-equal.html

 Thanks,
 JJ

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




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




Determining current function name

2010-12-30 Thread Parag Kalra
Hi,

Just like $0 reveals the current script name is there any variable
using which I can find the current sub-routine I am currently in.

Snippet of what I am looking for:

use strict;
use warnings;

sub foo_bar () {
print You are currently using the function -  $some_variable\n;
}

foo_bar;


Cheers,
Parag

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




Re: Determining current function name

2010-12-30 Thread Parag Kalra
I have already tried that.

Specially - caller(3) but it returns the details of the caller i.e
from where it was called and no particular details of where it is in.

Cheers,
Parag




On Thu, Dec 30, 2010 at 6:50 PM, Kenneth Wolcott
kennethwolc...@gmail.com wrote:
 On Thu, Dec 30, 2010 at 18:30, Parag Kalra paragka...@gmail.com wrote:
 Hi,

 Just like $0 reveals the current script name is there any variable
 using which I can find the current sub-routine I am currently in.

 Snippet of what I am looking for:

 use strict;
 use warnings;

 sub foo_bar () {
    print You are currently using the function -  $some_variable\n;
 }

 foo_bar;


 Cheers,
 Parag

 Hmmm...

 Try typing perldoc -f caller and see if that helps...

 Ken Wolcott

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




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




Re: Determining current function name

2010-12-30 Thread Parag Kalra
Thanks Shawn and Jim. caller(0) did the trick.

Cheers,
Parag




On Thu, Dec 30, 2010 at 8:11 PM, Jim Bauer holdsworth...@eml.cc wrote:
 On Thu, 30 Dec 2010 18:30:04 -0800, Parag Kalra wrote:
 Hi,

 Just like $0 reveals the current script name is there any variable
 using which I can find the current sub-routine I am currently in.
  printf(currently in %s\n, (caller(0))[3] =~ /^.+:(\w+)$/);

 See `perldoc -f caller'.
 ---


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




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




Behavior of Regex modifier /x

2010-12-27 Thread Parag Kalra
Hi,

I was under the impression that regex modifier '/x' ignores the white
space. So in following script both the if-else blocks should print
Match since the strings differ only in white space and '/x' should
ignore the white space.

But looks like my understanding of '/x' is wrong. Could someone please
correct me and explain the below behavior.

#!/usr/bin/perl
use strict;
use warnings;
my $str = Hello World;
my $str2 = Hello World;
my $str3 = HelloWorld;

if($str =~/$str2/x){
print Match\n;
} else {
print No Match\n;
}

if($str =~/$str3/x){
print Match\n;
} else {
print No Match\n;
}


Cheers,
Parag

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




Re: Behavior of Regex modifier /x

2010-12-27 Thread Parag Kalra
Thanks All.

With all these examples, now I see how /x works.

Cheers,
Parag




On Mon, Dec 27, 2010 at 2:39 PM, Tim Mitchell tmitch...@gmail.com wrote:
 Try my $str = HelloWorld;

 On Mon, Dec 27, 2010 at 2:34 PM, Parag Kalra paragka...@gmail.com wrote:

 Hi,

 I was under the impression that regex modifier '/x' ignores the white
 space. So in following script both the if-else blocks should print
 Match since the strings differ only in white space and '/x' should
 ignore the white space.

 But looks like my understanding of '/x' is wrong. Could someone please
 correct me and explain the below behavior.

 #!/usr/bin/perl
 use strict;
 use warnings;
 my $str = Hello World;
 my $str2 = Hello World;
 my $str3 = Hello    World;

 if($str =~/$str2/x){
    print Match\n;
 } else {
    print No Match\n;
 }

 if($str =~/$str3/x){
    print Match\n;
 } else {
    print No Match\n;
 }


 Cheers,
 Parag

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





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




Re: Perl Books

2010-12-26 Thread Parag Kalra
Learning Perl by Randal and Group - http://oreilly.com/catalog/9780596001322

Must must read book for any beginner.

Cheers,
Parag




On Sun, Dec 26, 2010 at 10:54 AM, SERIER stephenm.william...@gmail.com wrote:
 What are some of the best books for newbies to perl?


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




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




Re: using grep and hash to delete duplicate elements from an array

2010-12-19 Thread Parag Kalra
The approach to remove duplicate items looks good and to get rid of files
having same names but different paths, may be you can split the the path
name items using a forward slash (/) and then try to grep if the last item
(file name) is already a existing file and if it is then skip it.

Cheers,
Parag



On Wed, Dec 15, 2010 at 8:27 AM, Sooraj S soorajspadmanab...@gmail.comwrote:

 Hi,

 I have a file_list array containing paths to files. I want to delete
 duplicate elements from an array. Also i want to delete files with
 conflicting names ie those elements with same name but different path
 should also be deleted. I want this to be done with grep.

 my @file_list= qw(aa dd bb/aa cc dd kk/dd hh);
 my %exist=();
 # This removes all the duplicate elements.
 my @unique = grep { ! $exist { $_ }++ } @file_list;
 #This removes conflicting files.
 #Please give me your answer

 My output should be = cc hh


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





Re: Split function

2010-11-28 Thread Parag Kalra
How do i split a value like this
F:\test\test123\test1233

use strict;
use warnings;
my $str='F:\test\test123\test1233';
my @values = split /\\/, $str;
print @values;

Cheers,
Parag



On Sun, Nov 28, 2010 at 1:54 AM, Chaitanya Yanamadala 
dr.virus.in...@gmail.com wrote:

 How do i split a value like this
 F:\test\test123\test1233

 please help me with this..

 Regards
 Chaitanya



Re: chromatic's Modern Perl book is out.

2010-11-12 Thread Parag Kalra
Thanks for the update Shlomi.

Had already started reading this book (draft version) on your earlier
recommendation. Will continue to it from this final version.

Its a good book. Thanks once again for sharing the information.

Cheers,
Parag



On Fri, Nov 12, 2010 at 5:50 AM, Shlomi Fish shlo...@iglu.org.il wrote:

 Hi all,

 chromatic's Modern Perl book is finally out and is available as free PDFs
 downloads:

 http://www.modernperlbooks.com/mt/2010/11/the-book-is-out.html

 I have read the book and can recommend it for beginners.

 I should note that both Yuval Kogman and I have contributed to the book's
 proofreading process on github.

 Regards,

Shlomi Fish

 --
 -
 Shlomi Fish   http://www.shlomifish.org/
 Humanity - Parody of Modern Life - http://shlom.in/humanity

 rindolf She's a hot chick. But she smokes.
 go|dfish She can smoke as long as she's smokin'.

 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/





Re: xls files in perl

2010-11-12 Thread Parag Kalra
From professional experience, I would recommend:

Spreadsheet::ParseExcel

Cheers,
Parag



On Thu, Nov 11, 2010 at 7:09 AM, Anush anushajl...@gmail.com wrote:

 Is there any code for reading an xls file in perl.
 I found the following code from net, but it does not work. Please help
 me.


 #!/usr/bin/perl -w

 use strict;
 use Spreadsheet::Read;
 use Data::Dumper;

 my $xls = ReadData (Input/sample.xls);

 print $xls-[1]{'A1'};
 exit;


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





Re: Database table load utility

2010-11-08 Thread Parag Kalra
I'm in the thinking stages of creating a table-load utility, which reads a
tab-separated CSV file and inserts or updates rows in a relational table
(probably Oracle).  I don't think that will be too hard, having used Perl
DBI/DBD modules in the past.

Since you are planning to design your own table-load utility probably for
Oracle, I would like to share my own experience on this and  would just like
to add something to other aspects of your requirement.

1. First preference should always be SQLLDR (in direct mode probably)
provided you have Oracle client installed on the *Nix box.
2. If you can't use SQLLDR in direct mode, you can definitely use Perl to
load the data. The challenge here is how optimize you can design your
utility. And the best way to upload the data using Perl DBI/DBD is to use
DBD::Oracle in array interface mode. Refer the following link for the bench
marking results:

http://www.nntp.perl.org/group/perl.dbi.users/2010/05/msg34905.html


Cheers,
Parag
On Sun, Nov 7, 2010 at 4:16 PM, Chap Harrison c...@pobox.com wrote:

 Hi folks,

 I'm in the thinking stages of creating a table-load utility, which reads a
 tab-separated CSV file and inserts or updates rows in a relational table
 (probably Oracle).  I don't think that will be too hard, having used Perl
 DBI/DBD modules in the past.  What's different is that customers will
 transmit their files to a directory on a Linux server, using an FTP/SFTP
 client of their choosing, after which my utility needs to notice the
 arrival of the file, and initiate the table updating.

 Are there any Perl facilities, or modules, I should be considering for
 this?  Or is this sort of problem typically solved with something as
 primitive as a daemon that periodically polls for changes to the
 directories?

 And - is there perhaps a name for this kind of design?  (I mean, other than
 somewhat retarded ;-)  Kind of like store-and-forward, but different?
  That would help my googling.

 I do appreciate any follow-up questions or suggestions

 Chap


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





Re: error opening file with open function

2010-11-07 Thread Parag Kalra
Instead of taking the file as an input parameter, try to parse the file by
hard coding its name in the script and let us know the outcome.

Cheers,
Parag



On Sun, Nov 7, 2010 at 6:00 PM, J M jmd...@gmail.com wrote:

 Hi all,

 I'm having great issues with my program at the moment... it is supposed to
 take a csv file and parse it, with the output being stored in a MySQL
 database. The problem I'm having is that the file I need to parse
 ('ish_history.csv') will not open in the program for some reason. I know
 the
 file exists, I'm on a linux system and the file is world-readable, and I've
 tried placing the file in the directory the script is run from AS WELL as
 using full path names to said file... all has resulted in no luck, and I'm
 getting the No such file or directory error. Here is my code so far:



 [code]
 #! /usr/bin/perl
 #
 use DBI;
 use DBD::mysql;
 use Text::CSV;


 #configure variables
 my $host = localhost;
 my $db = somefakedatabase;
 my $table = somefaketable;
 my $user = somefakeuser;
 my $password = yeahrightlikethisismyrealpasswordLOL;

 #connect to the database
 my $dbc = dbi:mysql:$db:$host;
 if(my $dbh = DBI-connect($dbc, $user, $password) or die Can't connect to
 the
database: $DBI::errstr\n) {
print Connected to the database!;
 }

#setup parser
my $csv = Text::CSV-new();
print What is the name of the file? :  ;
chomp(my $file = STDIN);

open CSV, , $file or die Can't open the file \$file\: $!;
while(CSV) {
next if ($. == 1);
if ($csv-parse($_)) {
my @columns = $csv-fields();
my $myquery = $dbh-prepare('insert into $table

 (station_number,WBAN_number,station_name,country,fips,state,ICAO_callsign,lattitude,longitude,elevation)
 values ($columns[0], $columns[1], **truncated**
$myquery-execute();
$dbh-disconnect();
  } else {
  my $err = $csv-error_input;
  print Failed to parse line: $err;
}
   }
   close CSV;
   closedir TMPDIR;
 [\code]

 Any ideas as to why this isn't working?



Please suggest a good book on perl

2010-10-23 Thread Parag Kalra
Hey All,

Just finished reading 'intermediate perl' Enjoyed it as much as I
enjoyed the book 'learning perl'

Thanks Randal, Tom  All

Please now suggest another must read nook on perl.

Sent from my iPhone

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




Re: Please suggest a good book on perl

2010-10-23 Thread Parag Kalra
Ok. Are you referring to the one by Michael Saltzman

Btw I would also like to thank brain d foy for such a good book 'learning
perl'

Sent from my iPhone

On Oct 23, 2010, at 3:00 PM, Brian Fraser frase...@gmail.com wrote:

I was on your exact same situation a couple of weeks ago. Personally, I
tackled Programming Perl[0], but maybe you'd prefer reading chromatic's
Modern Perl[1]; Both require some previous knowledge -- Knowledge which you
gained by reading the Llama and the Alpaca, mostly (I'm still reading Modern
Perl, but the level seems just about perfect).

Although, if you prefer looking at code examples rather reading explanations
with code alongside, the Perl Cookbook[0], or maybe Perl Hacks[2] might suit
your tastes better (I read both of them during bus rides, which was slightly
tortuous; I couldn't wait to get to work/home to try things out).

And there's always Higher-Order Perl[3] and the third book of the trilogy,
Mastering Perl[0], if you feel ready for them. I can't say much about those
yet though, me not feeling ready yet and all.

Brian.

[0] http://perldoc.perl.org/perlfaq2.html#Perl-Books
[1] Draft:
http://www.modernperlbooks.com/mt/2010/10/modern-perl-the-book-the-draft-pdf.html
[2] http://oreilly.com/catalog/9780596526740
[3] http://hop.perl.plover.com


Re: perl real life exercise

2010-10-16 Thread Parag Kalra
I would suggest few things:

1. Maximum participation at perlmonks.org and beginners@perl.org (Not just
asking questions but monitoring these forums to answer as much as you can)
2. Using Perl, try to automate every computer related tasks which you do
frequently at your work place or may be at home
3 Read the book Intermediate Perl, extension to the book - 'Learning Perl'
4. Try to submit your own module to CPAN.

Cheers,
Parag



On Fri, Oct 15, 2010 at 12:02 AM, Agnello George
agnello.dso...@gmail.comwrote:

 HI

 Is there any site or any book other than learning perl where i would get
 real life exercises on perl scripting.

 Thanks

 --
 Regards
 Agnello D'souza



Re: Problem reading files

2010-10-16 Thread Parag Kalra
Hi Kryten,

Could you please post a sample content of the file and the actual content
that is being displayed by the script on your editor.

Also kind send the output of following script and check if its same as your
previous output.

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

#open my $configuration, 'temp.txt' or die my error: $! ;
my @info = DATA ;
chomp (@info);
foreach my $i (@info) { print $i\n  ; }


__DATA__
Hello World
How are you
I am good

And as Shlomi said try the scripts on different editors to nail down the
issue.

Cheers,
Parag



On Sat, Oct 16, 2010 at 1:48 AM, Shlomi Fish shlo...@iglu.org.il wrote:

 Hi Kryten,

 On Friday 15 October 2010 08:42:07 Kryten wrote:
  Hi,
  I'm hitting a strange problem running simple perlscript on my new
  laptop.
 
  To illustrate:-
 
  #!/usr/bin/perl
  use strict;
  use warnings;
  use diagnostics;
 
  open my $configuration, 'H:\temp.txt' or die my error: $! ;

 You may consider replacing \ with / - it works just as well inside Perl
 on
 Windows , and causes less troubles.

  my @info = $configuration ;
  chomp (@info);
  foreach my $i (@info) { print $i\n  ; }
  ## End
 
  When I run in either Primalscript or Hippoedit the output pane emits
  the 1st character
  of the 1st line in the H:\temp.txt file, preceded by a colon.

 Primalscript and Hippoedit appear to be non-open-source IDEs. Please try
 running the script from the command line (see
 http://sourceforge.net/projects/console/ ) and report the results.

 
  I realise this is the case because if I change the 1st line character
  to whatever, the
  re-run the code that's the character I get. It doesn't matter where
  the file is located.
  I have admin rights on the machine etc
 
  W7 x64 with Activeperl 5.12.2
 

 Did you also try http://strawberryperl.com/ ? It's an open-source
 distribution
 of Perl for Windows.

 Regards,

Shlomi Fish

 --
 -
 Shlomi Fish   http://www.shlomifish.org/
 The Case for File Swapping - http://shlom.in/file-swap

 rindolf She's a hot chick. But she smokes.
 go|dfish She can smoke as long as she's smokin'.

 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/





Re: split log file

2010-10-16 Thread Parag Kalra
use strict;
use warnings;
my %log;
while(DATA){
chomp;
my ($key, $value) = split /;/, $_;
push @{$log{$key}}, $value;
}

foreach my $k (keys %log){
  open my $k_fh, '', $k.log or die Could not open the file - $k.log
: $! \n;
  foreach my $v (@{$log{$k}})  {
  print $k_fh $k.';'.$v.\n or die Could not print to the file -
$k.log : $! \n;
  }
}

__DATA__
3_21_2010;11:12\\trafic info
3_21_2010;11:34\\trafic info
3_21_2010;13:21\\trafic info
3_22_2010;11:12\\trafic info
3_22_2010;11:34\\trafic info
3_22_2010;13:21\\trafic info
3_22_2010;11:12\\trafic info
3_23_2010;11:34\\trafic info
3_23_2010;13:21\\trafic info
3_23_2010;13:21\\trafic info
3_24_2010;11:12\\trafic info
3_24_2010;11:34\\trafic info
3_24_2010;13:21\\trafic info

Cheers,
Parag



On Thu, Oct 14, 2010 at 7:54 AM, yo RO lyn...@gmail.com wrote:

 Hello I need to split a log file per days
 I have a file in txt format and I want to create a file with all data
 from one day in one file
 I will give example

 I have this imput
 3_21_2010;11:12\\trafic info
 3_21_2010;11:34\\trafic info
 3_21_2010;13:21\\trafic info
 3_22_2010;11:12\\trafic info
 3_22_2010;11:34\\trafic info
 3_22_2010;13:21\\trafic info
 3_22_2010;11:12\\trafic info
 3_23_2010;11:34\\trafic info
 3_23_2010;13:21\\trafic info
 3_23_2010;13:21\\trafic info
 3_24_2010;11:12\\trafic info
 3_24_2010;11:34\\trafic info
 3_24_2010;13:21\\trafic info

 I want to have in output 3 file
 file 1: name  3_21_2010.log
 contain
 3_21_2010;11:12\\trafic info
 3_21_2010;11:34\\trafic info
 3_21_2010;13:21\\trafic info

 file 2 : 3_22_2010.log
 contain

 3_22_2010;11:12\\trafic info
 3_22_2010;11:34\\trafic info
 3_22_2010;13:21\\trafic info
 3_22_2010;11:12\\trafic info

 and like this
 please help help me with this


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





Re: How to parse email header

2010-10-12 Thread Parag Kalra
Could you please post an actual example of your email header.

Cheers,
Parag



On Tue, Oct 12, 2010 at 9:20 AM, S Pratap Singh kdari...@gmail.com wrote:

 Hello ,

 I am trying to write a script which can parse email header and based on
 certain criteria/parameter it will update the email subject detail in the
 database.

 I have written a code but it is taking too much time to execute the code
 and
 each process is utilizing 100% of its cpu resources allocated to the
 process.

 The code itself is too big so I can not paste it here since there are lots
 operation being performed on the email header after fetching the correct
 emails.

 However I am pasting the search string which I am using and I think it is
 only bugy.

 search_string =

 '(.*)(From:)(\s*)(.*)(\s*)(\...@*\s*)(\s*)(\S*\s*\S*\s*\S*\s*\S*\s*\S*)(s*)(.*)(\s*)(id)(\s*)(\w\w\w\w\w\w-\w\w\w\w\w\w-\w\w*)(\s*)(.*)(\s*)(for

 \...@\s*)(\s*)(;)(\s*)(\S*\s*\S*\s*\S*\s*\S*)(\s*)(\d\d:\d\d:\d\d)(.*)(\s*)(Subject:)(\s*)(.*)(\s*)[(Primary
 Hostname)](\s*)(.*)',

 I want to gather particular field from the email header along with the
 complete message.
 The field which I want to select from the email header are
 1 From address (Filed number 6)
 2 For address (Since mails being forwarded to my email address from else
 where) (Filed number 17)
 3 Date and Time (Filed number 22 and 24)
 4 Message ID (Filed number 14)
 5 Complete Subject Line (Filed number 29)
 6 Complete Body (Filed number 33)

 Above gives me the output but it takes too much time sometimes it takes 30
 min if multiple mail comes to email address since I am writing these
 details
 in a file at the moment but I am worried because I want to update all these
 details to my database.

 Is there any way around to sort this out and it should not take more than a
 sec to complete the task.

 I know the above search string is not perfect and it fails if mail header
 format is different . If someone can shed some light on this.

 I have very less experience in perl programming so if you want to ask any
 thing please ask me and if some could come over chat then it will be really
 appreciated.

 Thank you
 Pratap



Re: How to parse email header

2010-10-12 Thread Parag Kalra
Ok.

I think simpler option here would be:

1. Assign the email header string to a variable.
2. Split the variable (using delimiter : ) and assign the list values to a
hash.
3. Keys of this hash would be the field attributes and values would be the
actual values.
4. You can then either apply regex on the value sor can directly get the
desired value as per the requirement.

Cheers,
Parag



On Tue, Oct 12, 2010 at 9:56 AM, S Pratap Singh kdari...@gmail.com wrote:

 Here it is
 
 Return-path: no-re...@testdemo.com
 Envelope-to: sea...@example.com
 Delivery-date: Sat, 14 Aug 2010 18:08:06 -0700
 Received: from localhost.localdomain ([127.0.0.1]:58763
 helo=[192.168.0.122])
 by server.example.com with esmtpa (Exim 4.69)
 (envelope-from no-re...@testdemo.com)
 id 1OkRhm-0001XX-DY
 for sea...@example.com; Sat, 14 Aug 2010 18:08:06 -0700
 Received: from 192.68.0.34 ([192.68.0.34])
 (SquirrelMail authenticated user sea...@project.example.com)
 by 192.168.0.122 with HTTP;
 Sat, 14 Aug 2010 18:08:06 -0700
 Message-ID: 74e8b2237739aa507ffd1f8428cb3d1c.squir...@192.168.0.122
 Date: Sat, 14 Aug 2010 18:08:06 -0700
 Subject: [65515 - Seeking - Reply] Need help
 From: no-re...@testdemo.com
 To: sea...@example.com
 User-Agent: SquirrelMail/1.4.20
 MIME-Version: 1.0
 Content-Type: text/plain;charset=iso-8859-1
 Content-Transfer-Encoding: 8bit
 X-Priority: 3 (Normal)
 Importance: Normal

 sea...@example.com
 ===

 There are other headers too and they are bit different than this one so can
 it be generalized.

 Thank you
 Pratap




Re: How to parse email header

2010-10-12 Thread Parag Kalra
And in case : could also be present as a part of data, you should probably
look for regex as a delimiter for the split operation.

Cheers,
Parag



On Tue, Oct 12, 2010 at 10:05 AM, Parag Kalra paragka...@gmail.com wrote:

 Ok.

 I think simpler option here would be:

 1. Assign the email header string to a variable.
 2. Split the variable (using delimiter : ) and assign the list values to a
 hash.
 3. Keys of this hash would be the field attributes and values would be the
 actual values.
 4. You can then either apply regex on the value sor can directly get the
 desired value as per the requirement.

 Cheers,
 Parag



   On Tue, Oct 12, 2010 at 9:56 AM, S Pratap Singh kdari...@gmail.comwrote:

 Here it is
 
 Return-path: no-re...@testdemo.com
 Envelope-to: sea...@example.com
 Delivery-date: Sat, 14 Aug 2010 18:08:06 -0700
 Received: from localhost.localdomain ([127.0.0.1]:58763
 helo=[192.168.0.122])
 by server.example.com with esmtpa (Exim 4.69)
 (envelope-from no-re...@testdemo.com)
 id 1OkRhm-0001XX-DY
 for sea...@example.com; Sat, 14 Aug 2010 18:08:06 -0700
 Received: from 192.68.0.34 ([192.68.0.34])
 (SquirrelMail authenticated user sea...@project.example.com)
 by 192.168.0.122 with HTTP;
 Sat, 14 Aug 2010 18:08:06 -0700
 Message-ID: 74e8b2237739aa507ffd1f8428cb3d1c.squir...@192.168.0.122
 Date: Sat, 14 Aug 2010 18:08:06 -0700
 Subject: [65515 - Seeking - Reply] Need help
 From: no-re...@testdemo.com
 To: sea...@example.com
 User-Agent: SquirrelMail/1.4.20
 MIME-Version: 1.0
 Content-Type: text/plain;charset=iso-8859-1
 Content-Transfer-Encoding: 8bit
 X-Priority: 3 (Normal)
 Importance: Normal

 sea...@example.com
 ===

 There are other headers too and they are bit different than this one so
 can it be generalized.

 Thank you
 Pratap





Finding characters from the file encoded with - ISO8859_1

2010-10-07 Thread Parag Kalra
Hi All,

I have a file encoded with ISO8859_1

I wish to find and print all the characters from a certain range say between
224 and 255

ord function doesn't seem to work here. Any other work around.

Cheers,
Parag


Re: Finding characters from the file encoded with - ISO8859_1

2010-10-07 Thread Parag Kalra
By range I mean: http://htmlhelp.com/reference/charset/iso224-255.html

Cheers,
Parag



On Thu, Oct 7, 2010 at 2:17 PM, Parag Kalra paragka...@gmail.com wrote:

 Hi All,

 I have a file encoded with ISO8859_1

 I wish to find and print all the characters from a certain range say
 between 224 and 255

 ord function doesn't seem to work here. Any other work around.

 Cheers,
 Parag




Re: perl

2010-10-04 Thread Parag Kalra
Where do you want to login? I believe you are already subscribed to the
list.

Is this your first post?

Please post your exact question.

Cheers,
Parag



On Mon, Oct 4, 2010 at 9:49 AM, sheikh numan iqbal numan1...@gmail.comwrote:

 hi,

 i want to login and need help on perl...

 regards,
 numan



My first attempt to design a module

2010-10-03 Thread Parag Kalra
Hi All,

I am planning to design a small module that would make use of object
oriented concepts of Perl.

Since its my first attempt in the field of Oops, I would request Perl
experts to review the code design as and when I would share the new piece of
development for this module.

Basic idea of the module: In many projects, qa needs to validate database
tables by executing many sql queries (test cases). The category of these sql
queries could be:

1. Count sql queries where in count returned by each sql query should be
exactly equal to the known count
2. Count sql queries where in count returned by each sql query should be
more than known count.
3. Count sql queries where in count returned by each sql query should
be less than known count.
4. Minus sql queries (sql1 minus sql2) where in expected output is 'no rows
returned' meaning data set of the the sql queries is exactly same.

The test cases i.e. sql queries would be mentioned in configuration file
(called cfg) - 1 sql query per line.

The configuration file would be given for processing to appropriate method.
This method would then execute all the test cases and generate the detailed
results in the result directory specified by the user.

Please feel free to share your valuable suggestions.

PS: Its just the first version and with only 1 method. I plan to implement
the remaining 5-6 methods gradually.

The reason I want to get it reviewed is because if it turns out to be
success I would love to release it to CPAN

The module can be found at:
http://perlmonks.org/?abspart=1;displaytype=displaycode;node_id=863241;part=1

And the testing script can be found at:
http://perlmonks.org/?abspart=1;displaytype=displaycode;node_id=863241;part=2

Cheers,
Parag


Re: No Output in Terminal

2010-09-30 Thread Parag Kalra
Few questions/suggestions:

Which shell are you on? i.e echo $SHELL
whats the location of the perl binary: i.e which perl
Can you invoke the program using 'use strict' and let us know the output
Can you try this: perl -e 'print Hello World'

Cheers,
Parag



On Thu, Sep 30, 2010 at 7:25 PM, Mark herrpoe...@hailmail.net wrote:

  Hi. Perl newbie here. I'm on a MBP using Leopard (10.5.8). Perl is
 pre-installed: /usr/bin/perl.

 I can't get a simple Hello world script to work. Here's the script (saved
 as test.pl).

#!/usr/bin/perl -w
print Hello world!\n;

 Permissions are set to 755. In a terminal application (iTerm) I changed
 directory to the location of the script, and typed
perl test.pl
 Nothing happens -- i.e. no Hello world!, and I get a new command prompt.

 Typing
perl -v
 produces:
This is perl, v5.8.8 built for darwin-thread-multi-2level
...
 and so on.

 Typing
perl -c Test.pl
 yields
Test.pl syntax OK

 So how come no Hello world!?

 I really want Perl to have me at Hello World. What should I do?

 - Mark

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





Re: No Output in Terminal

2010-09-30 Thread Parag Kalra
Thats ^M character.

You can get rid of them using vi: :%s/^M//g

Cheers,
Parag



On Thu, Sep 30, 2010 at 8:26 PM, Mark herrpoe...@hailmail.net wrote:

  On 9/30/10 10:59 PM, Chas. Owens wrote:

 The only thing I can do to reproduce what you are seeing is to place a
 control-d (aka ASCII character 4) in the file.  Try saying this

 echo 'print hello\n' | perl -

 If that works, then try this:

 perl -nle 'print for grep { $_  31 or $_  126 } map ord, split //' t.pl

 It will tell use what control characters may be lurking in that file of
 yours.


 AH HA! When you mentioned control characters, I wondered if my text editor
 -- BBEdit -- was causing the problem. It must have been, because when I copy
  pasted the code from BBEdit into Emacs, suddenly the script ran perfectly
 in iTerm. Problem apparently solved. Thanks, everyone!

 - Mark



How to get the Pause ID

2010-09-29 Thread Parag Kalra
Hi All,

I have been trying to get Pause ID but seems like either the request is
getting rejected or something is wrong in the way I am raising the request.

I have applied twice in past.

EG: http://www.nntp.perl.org/group/perl.modules/2010/09/msg72805.html

Could someone please share some pointers on it.

Cheers,
Parag


Re: Good Perl Books

2010-09-24 Thread Parag Kalra
   Learning Perl
   by Randal L. Schwartz, Tom Phoenix, and brian d foy
   ISBN 0-596-52010-7 [5th edition June 2008]
   http://oreilly.com/catalog/9780596520106/

Must must must read book for any beginner.

Cheers,
Parag




On Fri, Sep 24, 2010 at 4:36 AM, Jeff Pang pa...@arcor.de wrote:
  from PerlFAQ: Recommended books on (or mostly on) Perl follow.


    References
                Programming Perl
                by Larry Wall, Tom Christiansen, and Jon Orwant
                ISBN 0-596-00027-8 [3rd edition July 2000]
                http://www.oreilly.com/catalog/pperl3/


                Perl 5 Pocket Reference
                by Johan Vromans
                ISBN 0-596-00374-9 [4th edition July 2002]
                http://www.oreilly.com/catalog/perlpr4/


    Tutorials
                Beginning Perl
                by James Lee
                ISBN 1-59059-391-X [2nd edition August 2004]
                http://apress.com/book/bookDisplay.html?bID=344


                Elements of Programming with Perl
                by Andrew L. Johnson
                ISBN 1-884777-80-5 [1st edition October 1999]
                http://www.manning.com/johnson/


                Learning Perl
                by Randal L. Schwartz, Tom Phoenix, and brian d foy
                ISBN 0-596-52010-7 [5th edition June 2008]
                http://oreilly.com/catalog/9780596520106/


                Intermediate Perl (the Alpaca Book)
                by Randal L. Schwartz and brian d foy, with Tom
 Phoenix (foreword by Damian Conway)
                ISBN 0-596-10206-2 [1st edition March 2006]
                http://www.oreilly.com/catalog/intermediateperl/


                Mastering Perl
                by brian d foy
                ISBN 0-596-52724-1 [1st edition July 2007]
                http://www.oreilly.com/catalog/9780596527242/


    Task-Oriented
                Writing Perl Modules for CPAN
                by Sam Tregar
                ISBN 1-59059-018-X [1st edition Aug 2002]
                http://apress.com/book/bookDisplay.html?bID=14


                The Perl Cookbook
                by Tom Christiansen and Nathan Torkington
                    with foreword by Larry Wall
                ISBN 1-56592-243-3 [1st edition August 1998]
                http://www.oreilly.com/catalog/cookbook/


                Effective Perl Programming
                by Joseph Hall
                ISBN 0-201-41975-0 [1st edition 1998]
                http://www.awl.com/


                Real World SQL Server Administration with Perl
                by Linchi Shea
                ISBN 1-59059-097-X [1st edition July 2003]
                http://apress.com/book/bookDisplay.html?bID=171


    Special Topics
                Perl Best Practices
                by Damian Conway
                ISBN: 0-596-00173-8 [1st edition July 2005]
                http://www.oreilly.com/catalog/perlbp/


                Higher Order Perl
                by Mark-Jason Dominus
                ISBN: 1558607013 [1st edition March 2005]
                http://hop.perl.plover.com/


                Perl 6 Now: The Core Ideas Illustrated with Perl 5
                by Scott Walters
                ISBN 1-59059-395-2 [1st edition December 2004]
                http://apress.com/book/bookDisplay.html?bID=355


                Mastering Regular Expressions
                by Jeffrey E. F. Friedl
                ISBN 0-596-00289-0 [2nd edition July 2002]
                http://www.oreilly.com/catalog/regex2/


                Network Programming with Perl
                by Lincoln Stein
                ISBN 0-201-61571-1 [1st edition 2001]
                http://www.awlonline.com/


                Object Oriented Perl
                Damian Conway
                    with foreword by Randal L. Schwartz
                ISBN 1-884777-79-1 [1st edition August 1999]
                http://www.manning.com/conway/


                Data Munging with Perl
                Dave Cross
                ISBN 1-930110-00-6 [1st edition 2001]
                http://www.manning.com/cross


                Mastering Perl/Tk
                by Steve Lidie and Nancy Walsh
                ISBN 1-56592-716-8 [1st edition January 2002]
                http://www.oreilly.com/catalog/mastperltk/


                Extending and Embedding Perl
                by Tim Jenness and Simon Cozens
                ISBN 1-930110-82-0 [1st edition August 2002]
                http://www.manning.com/jenness


                Perl Debugger Pocket Reference
                by Richard Foley
                ISBN 0-596-00503-2 [1st edition January 2004]
                http://www.oreilly.com/catalog/perldebugpr/


                Pro Perl Debugging
                by Richard Foley with Andy Lester
                ISBN 1-59059-454-1 [1st edition July 2005]
                http://www.apress.com/book/view/1590594541


 2010/9/24 Shlomi Fish 

Re: Web UI Automation

2010-09-23 Thread Parag Kalra
Selenium does provide Perl support.

http://release.seleniumhq.org/selenium-remote-control/1.0-beta-2/doc/perl/WWW-Selenium.html
Cheers,
Parag



On Thu, Sep 23, 2010 at 8:40 AM, Jatin daveyja...@gmail.com wrote:

 Hi

 I wanted to know if the UI automation for websites is possible using perl.
 I did some search on the net about the possible automation that can be done
 using perl but i mostly found information about the LWP bundle. My basic
 reading about it so far revealed that it cannot be used in automating user
 actions in the UI. So here i am with a few questions:

 -- Do we have any modules in perl that can help in automating the UI
 actions ?

 -- Does the LWP bundle help in automating all web protocols ?

 Appreciate your response in this regard.

 Thanks
 Jatin

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





Re: Interrupt Handling

2010-09-22 Thread Parag Kalra
$retval = `/$ENV{'ORACLE_HOME'}/bin/sqlplus -s  $QUERY_STRING  EOF 

One question out of curiosity. Actually 2 questions:

1. I am not sure if -s is a valid sqlplus option. I have always used -S to
operate in silent mode. I am using SQL*Plus: Release 10.2.0.4.0 - Production

2. Is there any specific need why you are supplying sql steps through EOF.
Its always advisable to try to invoke the queries/commands through proper
.sql file.

Cheers,
Parag



On Wed, Sep 22, 2010 at 11:04 AM, Gopal Karunakar gk.kalipuray...@gmail.com
 wrote:

 Hi,

   Here's the code pasted below. The sub basically executed an anonymous
 pl/sql block (which is executing fine). I want to make sure that the user
 will not be able to a ctrl-c and exit at the stage where the sql statements
 are getting executed.

   I tried declaring it as local but even then its hanging when i give the
 interrupt.


 sub CopyData
 {
  local $SIG{'INT'} = 'IGNORE';

  ($option, $sourceID, $targetID, ) = ($_[0], $_[1], $_[2]);

   $option =~ s/^\s*(\S*(?:\s+\S+)*)\s*$/$1/;
   $sourceID   =~ s/^\s*(\S*(?:\s+\S+)*)\s*$/$1/;
   $targetID   =~ s/^\s*(\S*(?:\s+\S+)*)\s*$/$1/;

   my $retval;

   $retval = `/$ENV{'ORACLE_HOME'}/bin/sqlplus -s  $QUERY_STRING  EOF 
 $db_log
   WHENEVER OSERROR EXIT 5 ROLLBACK;
   WHENEVER SQLERROR EXIT 10 ROLLBACK;
   SET SERVEROUTPUT ON SIZE 100;
   SET FEEDBACK OFF;
   set pagesize 0;
   set linesize 150;

   DECLARE





 COMMIT;

EXCEPTION

  WHEN OTHERS
   THEN


o_ret_message :=  'Exception occured -' || ' Module Name:' || g_msg
 || CHR(10) ||
  'Error Code: ' || SQLCODE || CHR(10) ||
  'Error Message: ' || SUBSTR(sqlerrm,1,2000) ;
DBMS_OUTPUT.PUT_LINE (o_ret_message);
DBMS_OUTPUT.PUT_LINE (DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);


ROLLBACK;

END;
 /

 EOF` ;

 return $retval;
 }


 Regards,

 GK.


 On 22 September 2010 22:57, C.DeRykus dery...@gmail.com wrote:

  On Sep 22, 6:53 am, gk.kalipuray...@gmail.com (Gopal Karunakar) wrote:
 
   I used the $SIG{'INT'} = 'IGNORE'; in a sub in my script so
 that
  the
   script while executing the particular sub will ignore the ctrl-c. And I
  gave
   $SIG{'INT'} = 'DEFAULT'; at the end of the sub to reset the behavior
 back
  to
   normal.
 
  Presuming your signal setting is the default on entry to
  the sub,  you can just use local to temporarily set the
  interrupt:
 
sub foo { local $SIG{INT} = 'IGNORE'; ... }
 
  The interrupt signal will be ignored for the scope of
  the sub. When the sub ends, the interrupt setting
  returns to its prior value.
 
   But when i give the ctrl-c the process seems to be hanging and I
   have to kill the process from the prompt. Is there any way to avoid
  getting
   this behavior?? When i give the ctrl-C the script should just ignore it
  and
   continue the process. I am on Sun Solaris box and using Perl version
  5.8.7.
  
 
  Are you sure there's only one exit point from the sub... ?
  That's a possible scenario which could bypass your
  $SIG{'INT'} = 'DEFAULT' reset at the end of the sub.
  (BTW, that's another advantage to using 'local')
 
  Show of the code too.  You can just pull out some of
  the relevant lines to give everyone a better view of the
  crime scene.  It's much easier to spot what might be
  happening.
 
  --
  Charles DeRykus
 
 
  --
  To unsubscribe, e-mail: beginners-unsubscr...@perl.org
  For additional commands, e-mail: beginners-h...@perl.org
  http://learn.perl.org/
 
 
 



Re: how to concatenate two lists

2010-09-20 Thread Parag Kalra
#!/usr/bin/perl
use strict;
use warnings;
my @ar = (rahul,patil);
my @ar1 = (nitin);
my @ar4;
push @ar4, (@ar, @ar1);
print @ar4;


Cheers,
Parag




On Mon, Sep 20, 2010 at 12:49 AM, rahul patil
rahul.deshmukhpa...@gmail.com wrote:
 Hello all,

 below is sample code i have written.Is it right way to declare ar4 which is
 concatenation of ar and ar1

 #!/usr/bin/perl
 @ar = {rahul,patil};
 @ar1 = {nitin};
 @ar4 = {...@ar,@ar1};
 print @ar4[2];

 if yes, why it is not printing output as nitin on my system

 --
 Regards,
 Rahul Patil


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




Re: One query

2010-09-19 Thread Parag Kalra
Hope this helps:

#!/usr/bin/perl
# Author: Parag Kalra
# Date: 19-SEPT-2010

use strict;
use warnings;

my %mean_values;

while(DATA){
  chomp;
  my ($key, $value) = split (/\t/,$_);

  if ( exists $mean_values{$key} ){
  push @{$mean_values{$key}}, $value;
  } else {
   ${$mean_values{$key}}[0] = $value;
  }
}

foreach (keys %mean_values){
my $cnt = @{$mean_values{$_}};
my $sum = 0;
foreach(@{$mean_values{$_}}){
   $sum = $sum + $_;
}

my $mean = $sum / $cnt;
print Key:'$_': | Values: '@{$mean_values{$_}} | Mean: $mean'\n;
}

__DATA__
NM_003273   1929.19
NM_053056   4662.262
NM_053056   5728.343
NM_024099   4009.705
NM_001085372685.4568
NR_003098   4700.29
NM_199337   2727.46
NM_018093   477.2938
NM_018093   813.0701


Cheers,
Parag




On Fri, Sep 17, 2010 at 6:41 AM, anamika : anamika...@gmail.com wrote:
 Hello,
 I have  a file like this:

 NM_003273       1929.19
 NM_053056       4662.262
 NM_053056       5728.343
 NM_024099       4009.705
 NM_001085372    685.4568
 NR_003098       4700.29
 NM_199337       2727.46
 NM_018093       477.2938
 NM_018093       813.0701


 I want it to be something like:
 If the elements in column 1 are same then take the mean of the values (in
 column 2) corresponding to these two/or more similar elements.
 Thanks in advance.


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




How to use the module: XML::Parser

2010-05-10 Thread Parag Kalra
Hey All,

I am trying to design some scripts using the module - XML::Parser

To start  learning I have a very basic scenario. Suppose I have following
XML file:

root
tag1My Tag1/tag1
tag2My Tag2/tag2
tag3My Tag3/tag3
/root

I want to save the the tags as the keys of a Hash and respective content as
the  value of that hash

So for the above XML file using the module XML::Parser, I would like to
create a hash having following key/value pair:

my %my_hash = (
tag1 = 'My Tag1',
tag2 = 'My Tag2',
tag3 = 'My Tag3',
);

Is that possible?

Cheers,
Parag


Perl modules to process PDF files

2010-05-03 Thread Parag Kalra
Hi All,

I need to process some PDF files to do some complex validation (like
checking the colour of icons, position etc). I was wondering if Perl comes
with some handy modules to process PDF files?

AFAIK even professional tools like QTP are not good with processing PDF
files.

Cheers,
Parag


Re: Redirecting the Output and Error of Perl script

2010-05-01 Thread Parag Kalra
Thanks all...

I was printing in normal fashion. I should have used something lik:

print STDERR stderr\n;

as suggested by all.

Cheers,
Parag



On Sat, May 1, 2010 at 1:55 AM, Philip Potter philip.g.pot...@gmail.comwrote:

 On 30 April 2010 18:45, Parag Kalra paragka...@gmail.com wrote:
  Hey All,
 
  I am trying to execute a Perl via shell script. I want to redirect output
 of
  Perl script to one file and error occured (if any) to other file.
 
  This is the snippet from my shell script:
 
  perl output_error.pl 1 Report.log 2Error.log
 

 What you have written works for me. I think your error is somewhere else.

 $ cat foo.pl
 #!perl

 print stdout\n;
 print STDERR stderr\n;

 $ perl foo.pl 1 out 2 err
 $ cat out
 stdout
 $ cat err
 stderr

 Note that  appends to the end of a file, while  replaces the file.

 Phil



Re: Interactive shell in Perl

2010-05-01 Thread Parag Kalra
I installed psh but getting following error after launching it:

Cannot find termcap: TERM not set at C:\perl\lib/Term/ReadLine.pm line 351

Cheers,
Parag



On Wed, Apr 28, 2010 at 7:45 AM, John W. Krahn jwkr...@shaw.ca wrote:

 Parag Kalra wrote:

 Hey All,


 Hello,


  Wanted to know if Perl has any interactive shell (just like Python, Bash,
 Ruby etc have) by any chance. And if yes how do we invoke that.


 perldoc -q Is there a Perl shell


 John
 --
 The programmer is fighting against the two most
 destructive forces in the universe: entropy and
 human stupidity.   -- Damian Conway


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





Redirecting the Output and Error of Perl script

2010-04-30 Thread Parag Kalra
Hey All,

I am trying to execute a Perl via shell script. I want to redirect output of
Perl script to one file and error occured (if any) to other file.

This is the snippet from my shell script:

perl output_error.pl 1 Report.log 2Error.log

However even normal print messages are going to Error.log. Any clue?

Cheers,
Parag


Interactive shell in Perl

2010-04-28 Thread Parag Kalra
Hey All,

Wanted to know if Perl has any interactive shell (just like Python, Bash,
Ruby etc have) by any chance. And if yes how do we invoke that.

Cheers,
Parag


Re: File Type

2010-04-13 Thread Parag Kalra
In case you are working on Unix, you can call the command on '*file*'
through Perl's function - '*system*'

Cheers,
Parag



On Tue, Apr 13, 2010 at 9:52 AM, Arun P Menon arunpme...@gmail.com wrote:

 Hi All,

 Could you tell which is the best perl module for finding file type?

 I am currently using File::Type but its missing out some (Shared
 libraries, c programs etc...). Is there any modules to search those
 files.

 --
 Regards,
 Arun Menon

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





How to create DSN on Solaris for Win32::ODBC

2010-04-08 Thread Parag Kalra
Hi All,

I am planing to use Win32::ODBC to connect to SQL Server from Solaris
through Perl.

I know how to create DSN on Windows. But doesn someone have any idea how I
can create dsn for Win32::ODBC on Solaris.

I am planning to use following:

bash-3.00$ pwd
/opt/oracle/product/10.2.0.4.0/perl/lib/site_perl/5.8.3/sun4-solaris-thread-multi/Win32
bash-3.00$ ls -l
total 10
-rwxr-xr-x   1 oracle   dba 4532 Jul  7  2004 DBIODBC.pm
bash-3.00$

Cheers,
Parag


How to convince the Customer

2010-03-17 Thread Parag Kalra
Hey All,

I am facing this situation where I have coded a Perl framework on Windows
and its all working fine. The framework mostly uses DBI and ODBC module to
connect to both Oracle server, execute SQL queries, fetch Rows etc etc.

Now the customer wants to use the framework on a Solaris machine (it has
Perl installed - 5.8.4). However that Solaris machine doesn't have DBI
module as a result of which I can't use my framework. But it has Oracle
client installed using which (sqlplus, sqlldr etc) I am able to connect to
the Oracle DB Server (located remotely)

Customer doesn't want to install anything third party that didn't come
pre-installed with Solaris box. However he may give a thought to installing
new version of standalone Perl which will have DBI module integrated. I
guess Perl 5.10.1 has DBI present by default. Could someone please confirm.

In addition to DBI do I need any other module to connect to Oracle DB from a
Solaris machine?

Is there a way I can convince the client that Perl is good OpenSource tool
and certainly not a malacious software.

Cheers,
Parag


Re: Any Good SCM tool to manage Perl Code locally

2010-03-16 Thread Parag Kalra
Yes  I have started using Git and I am very happy with it so far.

Just couple of questions - How can I make my code readonly using Git such
that it can be edited only when it is checked out.

Also if I want to take entire code base to particular revision, I guess I
need to use - 'git checkout commit_name'. So is commit name something like
- '11666c32ad1008a88a603d7ebc5cea144495789e'

Cheers,
Parag



2010/3/15 Eric Veith1 eric.ve...@de.ibm.com

 Jeremiah Foster jerem...@jeremiahfoster.com wrote on 03/15/2010 05:20:16
 PM:
  Shlomi mentioned git early on in this thread.

 You're right, sorry, I missed that one.

Eric

 --
 Eric MSP Veith eric.ve...@de.ibm.com
 Hechtsheimer Str. 2
 DE-55131 Mainz
 Germany

 IBM Deutschland GmbH
 Vorsitzender des Aufsichtsrats: Erich Clementi
 Geschäftsführung: Martin Jetter (Vorsitzender), Reinhard Reschke,
 Christoph Grandpierre, Matthias Hartmann, Michael Diemer, Martina
 Koederitz
 Sitz der Gesellschaft: Stuttgart
 Registergericht: Amtsgericht Stuttgart, HRB 14562
 WEEE-Reg.-Nr. DE 99369940

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





Any Good SCM tool to manage Perl Code locally

2010-03-13 Thread Parag Kalra
Hi All,

Although it is not related to Perl directly and might be little strange
question but still thought of consulting Perl gurus.

Here is the thing - I mainly code in Perl and Bash and I don't use any SCM
tool. And the reason I don't use it is because even if I configure a SCM
server - I should be able to access it both from home and work place (which
is unlikely to happen)

So wanted to know if it is a possible to use any free opensource tool to
manage code (only locally) where actual and current code resides in
different local directory and I can checkout code locally in some other
directory (in my working directory)

Cheers,
Parag


Re: regex support for glob

2010-01-20 Thread Parag Kalra
On the same lines I have question to all Perl Gurus. In this scenario can we
following? And if Yes, how efficient it is?

#!/usr/bin/perl
#Author: Parag Kalra

use strict;
use warnings;

# Creating 50 files - you can skip this
foreach(1..50){
open my $fh, '', 'file.'.$_;
}
my @Req_Input_Files;

# Getting first 30 files out of the lot of 50
foreach(1..30){
my $tmp_file = 'file.'.$_;
push @Req_Input_Files, glob $tmp_file;
}

print  @Req_Input_Files\n;

O/P:

perl Search_30_Files.pl

file.1 file.2 file.3 file.4 file.5 file.6 file.7 file.8 file.9 file.10
file.11 file.12 file.13 file.14 file.15 file.16 file.17 file.18 file.19
file.20
 file.21 file.22 file.23 file.24 file.25 file.26 file.27 file.28 file.29
file.30


Cheers,
Parag




On Wed, Jan 20, 2010 at 2:20 PM, Shameem Ahamed shameem.aha...@yahoo.comwrote:

 Hi All,

 I am wondering how can i use the glob  function to get only the first few
 files.


 I have files with digits as extensions. Like file.0, file.1
 file.2..file.100,file.101 etc.

 I want to select only the first 30 files.

 I used glob(file.[0-4]?[0-9]) but it doesn't seem to be working. The glob
 function trying to parse ? as separate, and matches all three digit
 extensions.

 How can i sort this out ?.

 Shammi





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





Searching First Array in Second Array

2010-01-19 Thread Parag Kalra
Hello All,

I have 2 arrays. I have written a script that searches each and every value
of first array in the second array. Each  every value of Source Array
should occur only once in the target array but it can occur anywhere.

If any of the source value doesn't occur or occur multiple times then the
script reports to the user.

This script is working fine for small arrays.

But I tried executing the script for 2 arrays each of which containing
around 7,00, elements and it is taking very long time.
I am using nested 'for' loops to make this search. How can I optimize it
further to search source array in target array.

Cheers,
Parag


  1   2   >