Re: Getting error- connect to Bugzilla(Certificate Authorities to trust)

2015-09-10 Thread Jitendra B
Thanks David, it resolved.

I am new to Bugzilla. I am really do not know where it went wrong in below
code snippet.
Error:


not well-formed (invalid token) at line 23, column 29, byte 846:

  enc1 = chr1 >> 2;

  enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);

^

  enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);

 at /Library/Perl/5.18/RPC/XML/Client.pm line 402. at
/Library/Perl/5.18/RPC/XML/Client.pm line 407.


Code Snnipet:

*

!/usr/bin/perl

#use strict;

use vars qw($VERSION);

use LEOCHARRE::CLI2 ':all','u:p:s:';

use LEOCHARRE::Dir ':all';

$VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /(\d+)/g;

use WWW::Bugzilla3;

use Net::SSL;

#use Smart::Comments '###';


$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;


#$opt_u or die("Missing username");

#$opt_p or die("Missing password");

#$opt_s or die("Missing site");


my $b = WWW::Bugzilla3->new( site => 'https://bugzilla.mysite.com' );

my $r = $b->login( "jbarik","xxx" ) or die("Could not login");

### $r

print "HI--HI : $r\n";

On Thu, Sep 10, 2015 at 11:30 AM, Omega -1911 <1911...@gmail.com> wrote:

> http://www.perlmonks.org/?node_id=892166
>
> Goggle is your friend.
>
> On Thu, Sep 10, 2015 at 1:54 AM, Jitendra B <jiten...@gmail.com> wrote:
>
>> Dear Sir/Madam,
>>
>> while I try to connect and query some data from bugzilla, I am getting
>> following error.
>>
>> Error:
>>
>> RPC::XML::Client::send_request: HTTP server error: Can't verify SSL peers
>> without knowing which Certificate Authorities to trust at
>> /Library/Perl/5.18/RPC/XML/Client.pm line 416.
>>
>>
>> Script:
>>
>>
>> #!/usr/bin/perl
>>
>> use strict;
>>
>> use vars qw($VERSION);
>>
>> use LEOCHARRE::CLI2 ':all','u:p:s:';
>>
>> use LEOCHARRE::Dir ':all';
>>
>> $VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /(\d+)/g;
>>
>> use WWW::Bugzilla3;
>>
>> use Net::SSL;
>>
>> use Smart::Comments '###';
>>
>>
>> $opt_u or die("Missing username");
>>
>> $opt_p or die("Missing password");
>>
>> $opt_s or die("Missing site");
>>
>>
>> my $b = WWW::Bugzilla3->new( site => $opt_s );
>>
>> my $r = $b->login( $opt_u, $opt_p ) or die("Could not login");
>>
>> ### $r
>>
>>
>> my @pids = $b->get_selectable_products(); # product ids
>>
>> ### product ids: @pids
>>
>> # get descriptive.. hashes..
>>
>>
>> my %product;
>>
>> for (@pids){
>>
>>my $p = ($b->get_products($_))[0];
>>
>>$product{$_} = $p;
>>
>> }
>>
>> ### %product
>>
>> my @all_bugs = $b->search;
>>
>> ### @all_bugs;
>>
>> my $count = scalar @all_bugs;
>>
>> warn("Have $count bugs");
>>
>> $count or exit;
>>
>> my @bugs = $b->get_bugs( @all_bugs ); # bug ids
>>
>> ## @bugs
>>
>> #my $c = scalar @bugs;
>>
>> #($c == 1) or warn("Got $c bugs in id $id, expected 1 only?");
>>
>> # get_bugs is weird
>>
>> BUG: for my $bug ( @bugs ){
>>
>>$bug->{internals}->{resolution} ||= 'OPEN';
>>
>>$bug->{internals}->{resolution}=~/INVALID|DUPLICATE/ and next BUG;
>>
>># example return for $bug
>>
>>
>>
>> ##   {
>>
>> ##alias => '',
>>
>> ##creation_time => '20090623T15:34:00',
>>
>> ##id => '15',
>>
>> ##internals => {
>>
>> ##   alias => '',
>>
>> ##   assigned_to => '1',
>>
>> ##   bug_file_loc => '',
>>
>> ##   bug_id => '15',
>>
>> ##   bug_severity => 'enhancement',
>>
>> ##   bug_status => 'RESOLVED',
>>
>> ##   cclist_accessible => '1',
>>
>> ##   cf_web_browser => '---',
>>
>> ##   component_id => '4',
>>
>> ##   creation_ts => '2009.06.23 15:34',
>>
>> ##   delta_ts => '2009-06-23 15:55:39',
>>
>> ##   everconfirmed => '1',
>>
>> #

Re: Getting error- connect to Bugzilla(Certificate Authorities to trust)

2015-09-10 Thread Jitendra B
As already I have install Net::SSL. and I am new user to Bugzilla. I am not
sure how to authenticate the certification.

Regards,
Jitendra

On Thu, Sep 10, 2015 at 11:30 AM, Omega -1911 <1911...@gmail.com> wrote:

> http://www.perlmonks.org/?node_id=892166
>
> Goggle is your friend.
>
> On Thu, Sep 10, 2015 at 1:54 AM, Jitendra B <jiten...@gmail.com> wrote:
>
>> Dear Sir/Madam,
>>
>> while I try to connect and query some data from bugzilla, I am getting
>> following error.
>>
>> Error:
>>
>> RPC::XML::Client::send_request: HTTP server error: Can't verify SSL peers
>> without knowing which Certificate Authorities to trust at
>> /Library/Perl/5.18/RPC/XML/Client.pm line 416.
>>
>>
>> Script:
>>
>>
>> #!/usr/bin/perl
>>
>> use strict;
>>
>> use vars qw($VERSION);
>>
>> use LEOCHARRE::CLI2 ':all','u:p:s:';
>>
>> use LEOCHARRE::Dir ':all';
>>
>> $VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /(\d+)/g;
>>
>> use WWW::Bugzilla3;
>>
>> use Net::SSL;
>>
>> use Smart::Comments '###';
>>
>>
>> $opt_u or die("Missing username");
>>
>> $opt_p or die("Missing password");
>>
>> $opt_s or die("Missing site");
>>
>>
>> my $b = WWW::Bugzilla3->new( site => $opt_s );
>>
>> my $r = $b->login( $opt_u, $opt_p ) or die("Could not login");
>>
>> ### $r
>>
>>
>> my @pids = $b->get_selectable_products(); # product ids
>>
>> ### product ids: @pids
>>
>> # get descriptive.. hashes..
>>
>>
>> my %product;
>>
>> for (@pids){
>>
>>my $p = ($b->get_products($_))[0];
>>
>>$product{$_} = $p;
>>
>> }
>>
>> ### %product
>>
>> my @all_bugs = $b->search;
>>
>> ### @all_bugs;
>>
>> my $count = scalar @all_bugs;
>>
>> warn("Have $count bugs");
>>
>> $count or exit;
>>
>> my @bugs = $b->get_bugs( @all_bugs ); # bug ids
>>
>> ## @bugs
>>
>> #my $c = scalar @bugs;
>>
>> #($c == 1) or warn("Got $c bugs in id $id, expected 1 only?");
>>
>> # get_bugs is weird
>>
>> BUG: for my $bug ( @bugs ){
>>
>>$bug->{internals}->{resolution} ||= 'OPEN';
>>
>>$bug->{internals}->{resolution}=~/INVALID|DUPLICATE/ and next BUG;
>>
>># example return for $bug
>>
>>
>>
>> ##   {
>>
>> ##alias => '',
>>
>> ##creation_time => '20090623T15:34:00',
>>
>> ##id => '15',
>>
>> ##internals => {
>>
>> ##   alias => '',
>>
>> ##   assigned_to => '1',
>>
>> ##   bug_file_loc => '',
>>
>> ##   bug_id => '15',
>>
>> ##   bug_severity => 'enhancement',
>>
>> ##   bug_status => 'RESOLVED',
>>
>> ##   cclist_accessible => '1',
>>
>> ##   cf_web_browser => '---',
>>
>> ##   component_id => '4',
>>
>> ##   creation_ts => '2009.06.23 15:34',
>>
>> ##   delta_ts => '2009-06-23 15:55:39',
>>
>> ##   everconfirmed => '1',
>>
>> ##   op_sys => 'All',
>>
>> ##   priority => 'P5',
>>
>> ##   product_id => '3',
>>
>> ##   qa_contact => '',
>>
>> ##   rep_platform => 'All',
>>
>> ##   reporter_accessible => '1',
>>
>> ##   reporter_id => '1',
>>
>> ##   resolution => 'FIXED',
>>
>> ##   short_desc => 'branding all the clients in
>> the dms',
>>
>> ##   status_whiteboard => '',
>>
>> ##   target_milestone => '---',
>>
>> ##   version => 'DMS2'
>>
>> ## },
>>
>> ##last_change_time => '20090623T15:55:39',
>>
>> ##summary => 'branding all the clients in the dms'
>>
>> ##  }
>>
>> ##]
>>
>>printf "---
>>
>> title: %s
>>
>> id: %0.3d
>>
>> product: %s
>>
>> status: %s
>>
>>
>> ",
>>
>>   $bug->{summary},
>>
>>   $bug->{id},
>>
>>   $product{ $bug->{internals}->{product_id} }->{name},
>>
>>   ( $bug->{internals}->{resolution} || 'OPEN'),
>>
>>
>>
>>;
>>
>>
>>
>> }
>>
>>
>> exit;
>>
>> sub usage {
>>
>>qq{$0 [OPTION]..
>>
>> Show bugzilla summary for bureaucracy.
>>
>>
>>-d  debug
>>
>>-h  help
>>
>>-v  version
>>
>>-p string   password
>>
>>-u string   username
>>
>>-s string   url of bugzilla website
>>
>>
>> Example Usage:
>>
>>
>>$0 -u jbarik -p hahaha -s https://bugzilla.mysite.com/
>>
>>
>> }}
>>
>>
>


Getting error- connect to Bugzilla(Certificate Authorities to trust)

2015-09-09 Thread Jitendra B
Dear Sir/Madam,

while I try to connect and query some data from bugzilla, I am getting
following error.

Error:

RPC::XML::Client::send_request: HTTP server error: Can't verify SSL peers
without knowing which Certificate Authorities to trust at
/Library/Perl/5.18/RPC/XML/Client.pm line 416.


Script:


#!/usr/bin/perl

use strict;

use vars qw($VERSION);

use LEOCHARRE::CLI2 ':all','u:p:s:';

use LEOCHARRE::Dir ':all';

$VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /(\d+)/g;

use WWW::Bugzilla3;

use Net::SSL;

use Smart::Comments '###';


$opt_u or die("Missing username");

$opt_p or die("Missing password");

$opt_s or die("Missing site");


my $b = WWW::Bugzilla3->new( site => $opt_s );

my $r = $b->login( $opt_u, $opt_p ) or die("Could not login");

### $r


my @pids = $b->get_selectable_products(); # product ids

### product ids: @pids

# get descriptive.. hashes..


my %product;

for (@pids){

   my $p = ($b->get_products($_))[0];

   $product{$_} = $p;

}

### %product

my @all_bugs = $b->search;

### @all_bugs;

my $count = scalar @all_bugs;

warn("Have $count bugs");

$count or exit;

my @bugs = $b->get_bugs( @all_bugs ); # bug ids

## @bugs

#my $c = scalar @bugs;

#($c == 1) or warn("Got $c bugs in id $id, expected 1 only?");

# get_bugs is weird

BUG: for my $bug ( @bugs ){

   $bug->{internals}->{resolution} ||= 'OPEN';

   $bug->{internals}->{resolution}=~/INVALID|DUPLICATE/ and next BUG;

   # example return for $bug



##   {

##alias => '',

##creation_time => '20090623T15:34:00',

##id => '15',

##internals => {

##   alias => '',

##   assigned_to => '1',

##   bug_file_loc => '',

##   bug_id => '15',

##   bug_severity => 'enhancement',

##   bug_status => 'RESOLVED',

##   cclist_accessible => '1',

##   cf_web_browser => '---',

##   component_id => '4',

##   creation_ts => '2009.06.23 15:34',

##   delta_ts => '2009-06-23 15:55:39',

##   everconfirmed => '1',

##   op_sys => 'All',

##   priority => 'P5',

##   product_id => '3',

##   qa_contact => '',

##   rep_platform => 'All',

##   reporter_accessible => '1',

##   reporter_id => '1',

##   resolution => 'FIXED',

##   short_desc => 'branding all the clients in the
dms',

##   status_whiteboard => '',

##   target_milestone => '---',

##   version => 'DMS2'

## },

##last_change_time => '20090623T15:55:39',

##summary => 'branding all the clients in the dms'

##  }

##]

   printf "---

title: %s

id: %0.3d

product: %s

status: %s


",

  $bug->{summary},

  $bug->{id},

  $product{ $bug->{internals}->{product_id} }->{name},

  ( $bug->{internals}->{resolution} || 'OPEN'),



   ;



}


exit;

sub usage {

   qq{$0 [OPTION]..

Show bugzilla summary for bureaucracy.


   -d  debug

   -h  help

   -v  version

   -p string   password

   -u string   username

   -s string   url of bugzilla website


Example Usage:


   $0 -u jbarik -p hahaha -s https://bugzilla.mysite.com/


}}


Perl file and STDERR

2013-07-09 Thread jitendra B
Hi All,


Can you please let me know the following snippset? why it is used for?


select( STDERR );
$| = 1;
select( STDOUT );
$| = 1;
print STDERR \nThis is india\n\n;
 print STDERR Usage: This is build;
 print STDERR where: base PL label\n;

and second question

 second question:- I want to open a file read+write mode and change the
some content in same file without creating another file and copy to it.

MY SCRIPT(Not working as i wish to )

#!/usr/bin/perl

open(FILE,test.txt) or die Could not open the file: $!;

@file=FILE;

foreach (@file)
{
  $_=~s/BLR/bangalore/g;

  print $_;
}
close(FILE);

Regards,
Jitendra


Re: Perl file and STDERR

2013-07-09 Thread jitendra B
Thank you very much Andy, Nathan, Shawn for your kind help.

I am new to the perl. Why auto-flush is needed here (STDERR autoflushes)?

It will free the memory or something else.

Regards,
Jitendra



On Tue, Jul 9, 2013 at 9:10 PM, Andy Bach afb...@gmail.com wrote:


 On Tue, Jul 9, 2013 at 9:37 AM, Nathan Hilterbrand noset...@cotse.netwrote:

 I want to open a file read+write mode and change
  the
  some content in same file without creating another file and copy to it.



 You might want to look at the perl in place mode [1], so something like
 perl -i.bak -pe ' s/BLR/bangalore/g;' myfile.txt

 will modifiy myfile.txt, as in a while loop (via the -p option:
 while ()   {
   s/BLR/bangalore/g;
 }

 ) and, as there a param to the -i option, leave you with the original text
 in a myfile.txt.bak file


 [1]
 perldoc perlrun has
  -i[extension]
 specifies that files processed by the  construct are to be
 edited in-place.  It does this by
 renaming the input file, opening the output file by the
 original name, and selecting that output file
 as the default for print() statements.  The extension, if
 supplied, is used to modify the name of the
 old file to make a backup copy, following these rules:

 If no extension is supplied, no backup is made and the current
 file is overwritten.

 If the extension doesn’t contain a *, then it is appended to
 the end of the current filename as a
 suffix.  If the extension does contain one or more *
 characters, then each * is replaced with the
 current filename.  In Perl terms, you could think of this as:

 ($backup = $extension) =~ s/\*/$file_name/g;

 This allows you to add a prefix to the backup file, instead of
 (or in addition to) a suffix:

 $ perl -pi'orig_*' -e 's/bar/baz/' fileA# backup to
 'orig_fileA'

 Or even to place backup copies of the original files into
 another directory (provided the directory
 already exists):

 $ perl -pi'old/*.orig' -e 's/bar/baz/' fileA # backup to
 'old/fileA.orig'

 These sets of one-liners are equivalent:

 $ perl -pi -e 's/bar/baz/' fileA# overwrite
 current file
 $ perl -pi'*' -e 's/bar/baz/' fileA # overwrite
 current file

 $ perl -pi'.orig' -e 's/bar/baz/' fileA # backup to
 'fileA.orig'
 $ perl -pi'*.orig' -e 's/bar/baz/' fileA# backup to
 'fileA.orig'

  From the shell, saying

 $ perl -p -i.orig -e s/foo/bar/; ... 

 is the same as using the program:

 #!/usr/bin/perl -pi.orig
 s/foo/bar/;

 which is equivalent to

 #!/usr/bin/perl
 $extension = '.orig';
 LINE: while () {
 if ($ARGV ne $oldargv) {
 if ($extension !~ /\*/) {
 $backup = $ARGV . $extension;
 }
 else {
 ($backup = $extension) =~ s/\*/$ARGV/g;
 }
 rename($ARGV, $backup);
 open(ARGVOUT, $ARGV);
 select(ARGVOUT);
 $oldargv = $ARGV;
 }
 s/foo/bar/;
 }
 continue {
 print;  # this prints to original filename
 }
 select(STDOUT);

 except that the -i form doesn’t need to compare $ARGV to
 $oldargv to know when the filename has
 changed.  It does, however, use ARGVOUT for the selected
 filehandle.  Note that STDOUT is restored as
 the default output filehandle after the loop.

 As shown above, Perl creates the backup file whether or not
 any output is actually changed.  So this is
 just a fancy way to copy files:

 $ perl -p -i'/some/file/path/*' -e 1 file1 file2 file3...
 or
 $ perl -p -i'.orig' -e 1 file1 file2 file3...
  You cannot use -i to create directories or to strip extensions from
 files.

 Perl does not expand ~ in filenames, which is good, since
 some folks use it for their backup files:

 $ perl -pi~ -e 's/foo/bar/' file1 file2 file3...

 Note that because -i renames or deletes the original file
 before creating a new file of the same name,
 UNIX-style soft and hard links will not be preserved.

 Finally, the -i switch does not impede execution when no files
 are given on the command line.  In this
 case, no backup is made (the original file cannot, of course,
 be determined) and processing proceeds
 from STDIN to STDOUT as might be expected.

 --

 a

 Andy Bach,
 

Perl to python converter

2011-12-23 Thread a b
Any thoughts?


Re: timings of perl subroutine with a program

2011-11-07 Thread a b
Thanks a ton!!

Hats off to you for encouragement

On Fri, Nov 4, 2011 at 5:05 PM, Shlomi Fish shlo...@shlomifish.org wrote:

 Hi a b,

 On Fri, 4 Nov 2011 15:18:00 +0530
 a b testa...@gmail.com wrote:

  apologize!!
 
  Can you help me to understand how async I/O can help me
 

 What's wrong with the resources in the URL I pointed you to? There's also
 http://en.wikipedia.org/wiki/Asynchronous_I/O which may be of interest.
 The Gods help them that help themselves. (
 http://en.wikiquote.org/wiki/Aesop ).

 Regards,

Shlomi Fish

  Regards
  a b
 
  On Thu, Nov 3, 2011 at 9:06 PM, Shlomi Fish shlo...@shlomifish.org
 wrote:
 
   Hello a b,
  
   please reply to the list as I specifically request in my signature.
   (Wretched
   gmail.com.) I'm CCing the list.
  
   On Thu, 3 Nov 2011 16:15:11 +0530
   a b testa...@gmail.com wrote:
  
Thanks Shlomi!!
   
I am not sure about async I/O?
   
any pointers about this one. It is new to me so far
   
  
   See the links from this URL:
  
   http://perl-begin.org/uses/multitasking/
  
   Regards,
  
  Shlomi Fish
  
   
Regards
~
   
On 11/3/11, Shlomi Fish shlo...@shlomifish.org wrote:
 On Thu, 3 Nov 2011 06:49:36 +0100
 timothy adigun 2teezp...@gmail.com wrote:

 Hi a b,

 a b testa...@gmail.com wrote:

  Hi all,
 
  i need to track down how much time each function is taking and
   anlyze if
  threads can help
 
  do we have any such function??
 

 **You can use ** use Benchmark qw(:all) **.
 From your CLI you can do: perldoc benchmark,
 or if you not like reading from the command Line Interface, you
 can
   do:
 perldoc -oHTML -dbenchmark.html benchmark,
 then you have your perldoc benchmark in html format then read how
 to
   use
 it --


 In addition, see:

 http://search.cpan.org/dist/Devel-NYTProf/

 Which is a sophisticated profiler for Perl.

 Other than that, threads may not be the answer due to the way they
 are
 implemented in Perl. Process forking or async IO may be better:

 http://perl-begin.org/uses/multitasking/

 Regards,

 Shlomi Fish

 --
 -
 Shlomi Fish   http://www.shlomifish.org/
 The Human Hacking Field Guide - http://shlom.in/hhfg

 Comedy is simply a funny way of being serious.
 — http://en.wikiquote.org/wiki/Peter_Ustinov

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

  
  
  
   --
   -
   Shlomi Fish   http://www.shlomifish.org/
   My Favourite FOSS - http://www.shlomifish.org/open-source/favourite/
  
   “You are banished! You are banished! You are banished!
   Hey! I’m just kidding!”
  
   Please reply to list if it's a mailing list post -
 http://shlom.in/reply .
  



 --
 -
 Shlomi Fish   http://www.shlomifish.org/
 The Human Hacking Field Guide - http://shlom.in/hhfg

 When Chuck Norris uses git, he takes a coffee break after initiating every
 git
 commit. And then he waits for the commit to finish.

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



Re: timings of perl subroutine with a program

2011-11-04 Thread a b
apologize!!

Can you help me to understand how async I/O can help me

Regards
a b

On Thu, Nov 3, 2011 at 9:06 PM, Shlomi Fish shlo...@shlomifish.org wrote:

 Hello a b,

 please reply to the list as I specifically request in my signature.
 (Wretched
 gmail.com.) I'm CCing the list.

 On Thu, 3 Nov 2011 16:15:11 +0530
 a b testa...@gmail.com wrote:

  Thanks Shlomi!!
 
  I am not sure about async I/O?
 
  any pointers about this one. It is new to me so far
 

 See the links from this URL:

 http://perl-begin.org/uses/multitasking/

 Regards,

Shlomi Fish

 
  Regards
  ~
 
  On 11/3/11, Shlomi Fish shlo...@shlomifish.org wrote:
   On Thu, 3 Nov 2011 06:49:36 +0100
   timothy adigun 2teezp...@gmail.com wrote:
  
   Hi a b,
  
   a b testa...@gmail.com wrote:
  
Hi all,
   
i need to track down how much time each function is taking and
 anlyze if
threads can help
   
do we have any such function??
   
  
   **You can use ** use Benchmark qw(:all) **.
   From your CLI you can do: perldoc benchmark,
   or if you not like reading from the command Line Interface, you can
 do:
   perldoc -oHTML -dbenchmark.html benchmark,
   then you have your perldoc benchmark in html format then read how to
 use
   it --
  
  
   In addition, see:
  
   http://search.cpan.org/dist/Devel-NYTProf/
  
   Which is a sophisticated profiler for Perl.
  
   Other than that, threads may not be the answer due to the way they are
   implemented in Perl. Process forking or async IO may be better:
  
   http://perl-begin.org/uses/multitasking/
  
   Regards,
  
   Shlomi Fish
  
   --
   -
   Shlomi Fish   http://www.shlomifish.org/
   The Human Hacking Field Guide - http://shlom.in/hhfg
  
   Comedy is simply a funny way of being serious.
   — http://en.wikiquote.org/wiki/Peter_Ustinov
  
   Please reply to list if it's a mailing list post -
 http://shlom.in/reply .
  



 --
 -
 Shlomi Fish   http://www.shlomifish.org/
 My Favourite FOSS - http://www.shlomifish.org/open-source/favourite/

 “You are banished! You are banished! You are banished!
 Hey! I’m just kidding!”

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



timings of perl subroutine with a program

2011-11-02 Thread a b
Hi all,

i need to track down how much time each function is taking and anlyze if
threads can help

do we have any such function??


Re: help: segmentation fault in threads program that use binmode

2011-07-12 Thread a b
Hi,

did you got your issue resolved!! I also face segmentation fault but without
binmode

I didn't found any solution any where and opted another solution

my program was using thread in loop till perl dump core with Out of memory
issue


Best of luck

~a b

On Thu, Jun 9, 2011 at 5:32 AM, anders lee jianghuma...@gmail.com wrote:


 when i use binmode in threaded program, i got a segmentation fault;

 i comment the binmode line, the program works well


 use threads;
 use threads::shared;

 use utf8;
 binmode(STDOUT, ':encoding(utf8)';

 ---thread create and join-



 --
 使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/

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





Re: How to truncate few bytes of file

2011-05-23 Thread a b
Hey Thanks uri!!!

Actually i have a global variable which contains information of all files
and their size

you have given great directions

Thanks all of you!!

Regards
a b


On Fri, May 20, 2011 at 9:39 PM, Uri Guttman u...@stemsystems.com wrote:

  ab == a b testa...@gmail.com writes:

   ab Hey Thanks all!
  ab I got it ;)

  ab open (FH, + $fname)|| die \nFailed to open file $fname\n;

 you don't need to open the file at all. truncate can take a filename.

  ab my $tmp=$fsize-$trunccount;

 where do those get set? don't name vars $tmp as that tells the reader
 nothing about the variable's use.

  ab seek(FH,$tmp,0);
  ab $addr = tell(FH) ;

 you don't need the seek and tell calls. you have the size you want and
 you can pass that directly to truncate.


  ab truncate(FH, $addr)|| die \nFailed to truncate $file: $!;
  ab close(fd);
  ab print \nTruncate successful\n;


 this can all be reduced to this:

my $size = -s $file ;
truncate( $file, $size - $truncount ) ||
 die \nFailed to truncate $file: $!;

 uri

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



How to truncate few bytes of file

2011-05-20 Thread a b
Hi All,

I need to truncate last few bytes of file. these files are big in size.

One idea is to write needed bytes to another file and delete the original
file, but i am dealing with big files :(

dont want to use truncate, it just truncating the size, all data is gone

any pointers

Thanks
a b


Re: How to truncate few bytes of file

2011-05-20 Thread a b
Hey Thanks all!

I got it ;)

open (FH, + $fname)|| die \nFailed to open file $fname\n;
my $tmp=$fsize-$trunccount;
seek(FH,$tmp,0);
$addr = tell(FH) ;
truncate(FH, $addr)|| die \nFailed to truncate $file: $!;
close(fd);
print \nTruncate successful\n;



On Fri, May 20, 2011 at 6:07 PM, Paul Johnson p...@pjcj.net wrote:

 On Fri, May 20, 2011 at 03:40:35PM +0530, a b wrote:

  Hi All,
 
  I need to truncate last few bytes of file. these files are big in size.
 
  One idea is to write needed bytes to another file and delete the original
  file, but i am dealing with big files :(
 
  dont want to use truncate, it just truncating the size, all data is gone
 
  any pointers

 truncate()'s second parameter is the length to which you want to
 truncate.  Did that not work for you?  If not, I would suggest posting
 some example code that fails, because calling truncate() seems to be the
 correct approach here.

 --
 Paul Johnson - p...@pjcj.net
 http://www.pjcj.net



Re: perl dd

2011-03-30 Thread a b
Thanks all!!

Can someone tell me if you have any experience in generating files
quickly(not sparse) in unix?

I want to generate millions of files under some directory

Thanks in Advance!

On Tue, Mar 29, 2011 at 10:27 PM, Filip Sneppe filip.sne...@gmail.comwrote:

 Hi,

 On Tue, Mar 29, 2011 at 4:57 PM, a b testa...@gmail.com wrote:
  Hey Chas,
 
  Thanks much for your reply. I actually want to have some more control
 over
  this.
 
  Thinking in way to initiate some in parallel also to get rid of OS
  specific things [if there]
 
 dd is really pretty limited if you want to use it as a IO benchmarking tool
 and automate stuff with it via Perl.

 Perhaps you want to look at more powerful IO load tools like IOzone.
 As it happens, a quick google search tells me that IOzone actually has
 some Perl modules to parse its output.

 Good luck  best regards,
 Filip



Re: perl dd

2011-03-29 Thread a b
Hey Chas,

Thanks much for your reply. I actually want to have some more control over
this.

Thinking in way to initiate some in parallel also to get rid of OS
specific things [if there]

thought of minimizing effort to run something which you suggested below. But
seems like, the only option in this galaxy :(

Thanks Everyone
Regards,
a b

On Mon, Mar 28, 2011 at 6:10 PM, Chas. Owens chas.ow...@gmail.com wrote:

 On Mon, Mar 28, 2011 at 05:22, a b testa...@gmail.com wrote:
  Thanks Rob
 
  I too was thinking that way. Just in case if any one might have face this
  issue and hence this email
 
  Well if no module i will live with it for time being
 snip

 The Unix dd command is a swiss army knife of copying data, could you
 narrow it down to what you want to use dd for?  A simple
 implementation would be

 #!/usr/bin/perl

 use strict;
 use warnings;

 die usage: $0 infile outfile\n unless @ARGV == 2;

 open my $in, :raw, $ARGV[0]
or die could not open $ARGV[0]: $!\n;
 open my $out, :raw, $ARGV[1]
or die could not open $ARGV[1]: $!\n;

 local $/ = \4096; #read 4k at a time

 print $out $_ while $in;



 --
 Chas. Owens
 wonkden.net
 The most important skill a programmer can have is the ability to read.



perl dd

2011-03-28 Thread a b
Hi,

I want to know if any module for dd in perl is available.

Any pointers will a great help

Thanks,
a b


Re: perl dd

2011-03-28 Thread a b
Hey Rob,


Yes, you are right
Thanks to mention this out.

I was referring to unix dd command. was wondering if we have any module
already available.

i didn't found on cpan

Thx
a b

On Mon, Mar 28, 2011 at 2:05 PM, Rob Coops rco...@gmail.com wrote:



 On Mon, Mar 28, 2011 at 10:18 AM, a b testa...@gmail.com wrote:

 Hi,

 I want to know if any module for dd in perl is available.

 Any pointers will a great help

 Thanks,
 a b


 Have you tried having a look at search.cpan.org?
 Oh, by the way what does dd stand for? Acronyms are great and all but
 unless you are asking the guy next to you working with the same acronyms on
 a daily basis it is unlikely that others will know what it is that you are
 talking about.

 Regards,

 Rob



Re: perl dd

2011-03-28 Thread a b
Thanks Rob

I too was thinking that way. Just in case if any one might have face this
issue and hence this email

Well if no module i will live with it for time being

Regards,
a b

On Mon, Mar 28, 2011 at 2:46 PM, Rob Coops rco...@gmail.com wrote:

 I had a quick look but I can only see people making system calls using
 system() or exec() etc... which sort of makes sense as there is no such
 command on pretty much any system except for *nix systems. I think you might
 simply have to write your own implementation or simply rely on system calls
 to get this done. IT will mean though that you code will not be very
 portable as it will only work on *nix systems and not on pretty much
 anything else.

 Regards,

 Rob


 On Mon, Mar 28, 2011 at 11:05 AM, a b testa...@gmail.com wrote:

 Hey Rob,


 Yes, you are right
 Thanks to mention this out.

 I was referring to unix dd command. was wondering if we have any module
 already available.

 i didn't found on cpan

 Thx
 a b

 On Mon, Mar 28, 2011 at 2:05 PM, Rob Coops rco...@gmail.com wrote:



 On Mon, Mar 28, 2011 at 10:18 AM, a b testa...@gmail.com wrote:

 Hi,

 I want to know if any module for dd in perl is available.

 Any pointers will a great help

 Thanks,
 a b


 Have you tried having a look at search.cpan.org?
 Oh, by the way what does dd stand for? Acronyms are great and all but
 unless you are asking the guy next to you working with the same acronyms on
 a daily basis it is unlikely that others will know what it is that you are
 talking about.

 Regards,

 Rob






Re: custom module and lib

2011-02-08 Thread a b
Hi All,

I just tweak some of the regular modules under my lib and those who denied
made it as pre-reqs

I am still fighting for my exact solution


On Thu, Feb 3, 2011 at 9:23 PM, Octavian Rasnita orasn...@gmail.com wrote:

 If you got a solution, it could be helpful for those who will find this
 thread on the web if you would explain what you did.

 Octavian
 --
 From: a b testa...@gmail.com
  Thanks a lot all for your views!! i got my solution
 
  Regards,
  a b
 
  On Mon, Jan 31, 2011 at 10:48 PM, Rob Dixon rob.di...@gmx.com wrote:
 
  On 31/01/2011 09:27, a b wrote:
 
 
  Making it more clear.
 
  I want to make tar ball which contains my perl  scripts and no other
  dependencies required. like Net::Rsh,Net::Telnet etc
  once user untar it, he should be able to run it from anywhere without
 any
  extra perl modules. I am thinking that might be Net::Rsh etc is not
  available on target m/c
 
  With above requirement, i want Net::Rsh like modules to be in my lib.
 Not
  sure if i need to modify Rsh module to get rid of scoping Net::
 
  I want to simply use this module as use Rsh;
 
  Can some body let me know if i can make these modules to my lib :0
 
  help much appeciated!!!
 
 
  Do you have a special reason for wanting to rename Net::Rsh to Rsh? It
 is a
  dangerous thing to do, as there may well be code that relies on the name
 of
  the module being unchanged. In particular you will have to edit the
 Rsh.pm
  file to say 'package Rsh', and it thereby becomes non-standard and so a
  maintenance problem.
 
  It is worth noting that, by default, the last entry in @INC is '.' - the
  current directory - so perl will ultimately look in the same directory
 as
  the calling program for all modules if they are not found elsewhere. So
 you
  can simple bundle Net::Rsh in the same place as your main program and
 any
  other modules.
 
  HTH,
 
  Rob
 
 

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





Re: custom module and lib

2011-02-03 Thread a b
Thanks a lot all for your views!! i got my solution

Regards,
a b

On Mon, Jan 31, 2011 at 10:48 PM, Rob Dixon rob.di...@gmx.com wrote:

 On 31/01/2011 09:27, a b wrote:


 Making it more clear.

 I want to make tar ball which contains my perl  scripts and no other
 dependencies required. like Net::Rsh,Net::Telnet etc
 once user untar it, he should be able to run it from anywhere without any
 extra perl modules. I am thinking that might be Net::Rsh etc is not
 available on target m/c

 With above requirement, i want Net::Rsh like modules to be in my lib. Not
 sure if i need to modify Rsh module to get rid of scoping Net::

 I want to simply use this module as use Rsh;

 Can some body let me know if i can make these modules to my lib :0

 help much appeciated!!!


 Do you have a special reason for wanting to rename Net::Rsh to Rsh? It is a
 dangerous thing to do, as there may well be code that relies on the name of
 the module being unchanged. In particular you will have to edit the Rsh.pm
 file to say 'package Rsh', and it thereby becomes non-standard and so a
 maintenance problem.

 It is worth noting that, by default, the last entry in @INC is '.' - the
 current directory - so perl will ultimately look in the same directory as
 the calling program for all modules if they are not found elsewhere. So you
 can simple bundle Net::Rsh in the same place as your main program and any
 other modules.

 HTH,

 Rob



Re: custom module and lib

2011-01-31 Thread a b
Thanks much for your response!!

Making it more clear.

I want to make tar ball which contains my perl  scripts and no other
dependencies required. like Net::Rsh,Net::Telnet etc
once user untar it, he should be able to run it from anywhere without any
extra perl modules. I am thinking that might be Net::Rsh etc is not
available on target m/c

With above requirement, i want Net::Rsh like modules to be in my lib. Not
sure if i need to modify Rsh module to get rid of scoping Net::

I want to simply use this module as use Rsh;

Can some body let me know if i can make these modules to my lib :0

help much appeciated!!!

Regards,
a b

On Sun, Jan 30, 2011 at 9:07 PM, Rob Dixon rob.di...@gmx.com wrote:

 On 30/01/2011 14:09, a b wrote:


 I have a query regarding using lib modules

 1) I've some custom modules which uses various default routines like
 Net::rsh etc

 Now, i want to pack all default routines into my lib and use that lib
 in my custom modules i.e

 package MyModule;

 use lib lib/test;(here i am placing my Rsh.pm etc modules and some of my
 custom modules)
 use Rsh;


 Is this possible???

 Please let me know how to go with this approach

 My motive is to create a main PM file which will call all small PM
 files(custom and defaults)


 I'm not clear what you need to do. What is a 'default routine'?

 At a guess you want to be able to access Net::Rsh as well as your own
 custom modules, in which case you probably don't understand how 'use lib'
 works, which is simply to add the path(s) you specify to the end of the list
 in @INC where perl will search for the modules you use. That means that,
 even after you have done 'use lib lib/test' you can still 'use Net::Rsh'
 and it will be found, as its location is still in @INC.

 For instance, something like

  use warnings;
  use strict;

  use lib 'lib/test';

  use Net::Rsh;
  use SpecialModule;

 will find Net/Rsh.pm whereever it is on your machine, as well as
 lib/test/SpecialModule.pm

 If this isn't what you're looking for then please post again.

 HTH,

 Rob



custom module and lib

2011-01-30 Thread a b
Hello All,

I have a query regarding using lib modules

1) I've some custom modules which uses various default routines like
Net::rsh etc
Now, i want to pack all default routines into my lib and use that lib in my
custom modules
i.e

package MyModule;

use lib lib/test;(here i am placing my Rsh.pm etc modules and some of my
custom modules)
use Rsh;


Is this possible???

Please let me know how to go with this approach

My motive is to create a main PM file which will call all small PM
files(custom and defaults)

Thanks in Advance!


Re: Reading a value from a hash using a variable for the key

2011-01-24 Thread Eyal B.
If so, how print TTL = $line\n does give me the right value ! (I
get  TTL = 125 if ping to Windows machine.

Thanks, for your answers.

On Jan 21, 4:30 pm, rob.di...@gmx.com (Rob Dixon) wrote:
 On 21/01/2011 05:50, Erez Schatz wrote:



  On 20 January 2011 15:38, Eyal B.ewinst...@gmail.com  wrote:

  I'm getting an error on the line where I should use the TTL variable -
  and take the right value from the hash (%list) :Use of uninitialized
  value in print at D:\system\perl\os-rec\os-rec5_.pl line 24
  ,HANDLE  line 3.

  Any idea ?
                          if($line =~ TTL=)
                                          {
                                  $line =~ s/.*TTL=//;
                                  print TTL = $line\n;
                                  print $list{$line} ;
                                  # print Machine $machine_IP is 
  $list{$line} ;
                                  last;                                   }

  Assuming a specific line is made of nothing but TTL=, then $line =~
  s/.*TTL=//; will erase the line, leaving you with an empty
  (uninitialized) $line variable.

 No it won't, it will leave $line containing a null (zero-length) string.
 There is no way to change a string value to uninitialized (undef) by
 deleting characters from it.

 - Rob


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




Re: Reading a value from a hash using a variable for the key

2011-01-24 Thread Eyal B.
On Jan 21, 11:42 pm, ewinst...@gmail.com (Eyal B.) wrote:
 On Jan 21, 4:30 pm, rob.di...@gmx.com (Rob Dixon) wrote:



  On 21/01/2011 05:50, Erez Schatz wrote:

   On 20 January 2011 15:38, Eyal B.ewinst...@gmail.com  wrote:

   I'm getting an error on the line where I should use the TTL variable -
   and take the right value from the hash (%list) :Use of uninitialized
   value in print at D:\system\perl\os-rec\os-rec5_.pl line 24
   ,HANDLE  line 3.

   Any idea ?
                           if($line =~ TTL=)
                                           {
                                   $line =~ s/.*TTL=//;
                                   print TTL = $line\n;
                                   print $list{$line} ;
                                   # print Machine $machine_IP is 
   $list{$line} ;
                                   last;                                   }
 I found the issue, and resolve it
 This regex clean unnecessary, extra digits: $line =~/.*TTL=\s*(\S+)\s*$/;


   Assuming a specific line is made of nothing but TTL=, then $line =~
   s/.*TTL=//; will erase the line, leaving you with an empty
   (uninitialized) $line variable.

  No it won't, it will leave $line containing a null (zero-length) string.
  There is no way to change a string value to uninitialized (undef) by
  deleting characters from it.

  - Rob

 ok. So why on print TTL = $line\n; I do get TTL = 125, if it's
 undefined ?
 Thanks, Rob, for your answer.


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




Re: Reading a value from a hash using a variable for the key

2011-01-23 Thread Eyal B.
On Jan 21, 4:30 pm, rob.di...@gmx.com (Rob Dixon) wrote:
 On 21/01/2011 05:50, Erez Schatz wrote:



  On 20 January 2011 15:38, Eyal B.ewinst...@gmail.com  wrote:

  I'm getting an error on the line where I should use the TTL variable -
  and take the right value from the hash (%list) :Use of uninitialized
  value in print at D:\system\perl\os-rec\os-rec5_.pl line 24
  ,HANDLE  line 3.

  Any idea ?
                          if($line =~ TTL=)
                                          {
                                  $line =~ s/.*TTL=//;
                                  print TTL = $line\n;
                                  print $list{$line} ;
                                  # print Machine $machine_IP is 
  $list{$line} ;
                                  last;                                   }

  Assuming a specific line is made of nothing but TTL=, then $line =~
  s/.*TTL=//; will erase the line, leaving you with an empty
  (uninitialized) $line variable.

 No it won't, it will leave $line containing a null (zero-length) string.
 There is no way to change a string value to uninitialized (undef) by
 deleting characters from it.

 - Rob

ok. So why on print TTL = $line\n; I do get TTL = 125, if it's
undefined ?
Thanks, Rob, for your answer.


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




Re: Reading a value from a hash using a variable for the key

2011-01-21 Thread Eyal B.
Tried to implement your recommendations  step by step .

#! C:\Perl\bin\perl
use strict;
use warnings;

my %list = (60=linux,61=linux,62=linux,63=linux,
64=linux,65=linux,125=Windows,126=Windows,127=Windows,
128=Windows,250=Unix,251=Unix,252=Unix,253=Unix,
254=Unix,255=Unix, 256=Unix,257=Unix,258=Unix,
259=Unix,260=Unix);

my $path = hosts.txt ;
# open (MACHINES,$path) or die Couldn't open file for writing;
open my $input_fh, , $path
or die Could not open '$path' - $!;

# Shlomi, you wrote : Use three args open and don't use bareword file
handles...

# I'm asking : Trying to implement that (Though, didn't understand
what is bareword)where do I indicate the MACHINES handle ?

my $machine_IP ;
while ($machine_IP = MACHINES)
{
chomp($machine_IP) ;
my $line ;
my $cmd ;
$cmd = ping $machine_IP;
open(HANDLE,$cmd|);

# Shlomi, you wrote : You should use three-args open, lexical
filehandles and or die.
# I'm  asking : Can you pls show me how should I write that ?
# Furthermore, use $cmd is not needed here as you can interpolate
directly from $cmd.
# I didn't understand what that means.

while ($line = HANDLE)
{
if($line =~ TTL=)

# No need for wrapping $line in double quotes here as $line is a
string.
# as mentioned above


 {
$line =~ s/.*TTL=//;
print TTL = $line\n;
print $list{$line} ;
last;   
}
# You can do all that in one regex match.
# I didn't reach so far ... Is that

# if (my ($ttl) = $line =~ m{TTL=(\d+)})

   # print Machine $machine_IP is
$list{$line} ;


}
   }
close HANDLE;
close MACHINES;

# Without make the changes about the File Handle -
I still got the error : Use of uninitialized value within %list in
print at C:\system\Perl\OS-recognize\os-rec5.1_.pl line 35, HANDLE
line 4.

Thanks, Shlomi,

Eyal.


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




Re: Reading a value from a hash using a variable for the key

2011-01-21 Thread Eyal B.
On Jan 21, 7:50 am, moonb...@gmail.com (Erez Schatz) wrote:
 On 20 January 2011 15:38, Eyal B. ewinst...@gmail.com wrote:



  I'm writing a scripts that check the TTL of the ping and found the OS.
  According the TTL - the script should let me know which OS it is :
  Linux/ Windows or Unix (Hash table)

  I'm getting an error on the line where I should use the TTL variable -
  and take the right value from the hash (%list) :Use of uninitialized
  value in print at D:\system\perl\os-rec\os-rec5_.pl line 24
  , HANDLE line 3.

  Any idea ?
                         if($line =~ TTL=)
                                         {
                                 $line =~ s/.*TTL=//;
                                 print TTL = $line\n;
                                 print $list{$line} ;
                                 # print Machine $machine_IP is 
  $list{$line} ;
                                 last;                                   }

 Assuming a specific line is made of nothing but TTL=, then $line =~
 s/.*TTL=//; will erase the line, leaving you with an empty
 (uninitialized) $line variable.

 A way to debug this will be to include a print $line just before the
 substitution, so you could find what is happening in each stage of the
 iteration.

 --
 Erez

 La perfection soit atteinte non quand il n'ya plus rien à ajouter,
 mais quand il n'ya plus rien à retrancher.

Hi Erez
print TTL = $line\n;  Does give me the right value ! (I.e TTL = 125)
Also print $list{125} ; return the right value
But this is not working : print $list{$line} ;
What can happen for the variable ?


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




Reading a value from a hash using a variable for the key

2011-01-20 Thread Eyal B.
I'm writing a scripts that check the TTL of the ping and found the OS.
According the TTL - the script should let me know which OS it is :
Linux/ Windows or Unix (Hash table)

I'm getting an error on the line where I should use the TTL variable -
and take the right value from the hash (%list) :Use of uninitialized
value in print at D:\system\perl\os-rec\os-rec5_.pl line 24
, HANDLE line 3.

Any idea ?


#! C:\Perl\bin\perl -w
use strict;
use warnings;

my %list = (60,linux,61,linux,62,linux,63,linux,64,linux,
65,linux,125,Windows,126,Windows,127,Windows,128,Windows,
250,Unix,251,Unix,252,Unix,253,Unix,254,Unix,255,Unix,
256,Unix,257,Unix,258,Unix,259,Unix,260,Unix);
my $path = hosts.txt ;
my $machine_IP ;
my $cmd ;

# read machines hosts names List from the txt file c:1.txt and take
the TTL data to th e variable: $line
open (MACHINES,$path) or die Couldn't open file for writing;
while ($machine_IP = MACHINES)
{
chomp($machine_IP) ;
my $line ;
$cmd = ping $machine_IP;
open(HANDLE,$cmd|);
while ($line = HANDLE)
{
if($line =~ TTL=)
{
$line =~ s/.*TTL=//;
print TTL = $line\n;
print $list{$line} ;
# print Machine $machine_IP is $list{$line} ;
last;   }
}
}
close HANDLE;
close MACHINES;


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




Re: Print FH to file.

2010-10-25 Thread KA B
On Oct 23, 6:45 pm, shlo...@iglu.org.il (Shlomi Fish) wrote:
 Hi KA B,

 On Friday 22 October 2010 21:12:29 KA B wrote:

  I`m trying to get the filehandler 1 and 2 to print the result in one
  line.

 It's filehandles - not filehandlers.

  The script i have made makes 2 lines.

  The script goes like this:

  my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;

 Do you have strict and warnings? Also see:

 http://perl-begin.org/tutorials/bad-elements/

 And you should probably use a date+time module:

 http://perl-begin.org/topics/date-and-time/

  $year += 1900;
  $mon += 1;
  open FH,echo $year-$mon-$yday $hour:$min  /home/me/scriptest/
  calls_BH |;
  while (FH) {
      print;
  }
  close FH;

 What are you trying to do here? Use three-args open (see the bad-elements link
 above), and don't resort to shell tricks for what can be done in Perl. You're
 appending the echo command's STDOUT to a file and then you're trying to pipe
 it out to Perl, but there won't be anything to pipe. This can be done in pure-
 Perl using File I/O.

  open FH1, snmpget -v1 -c mee 1.2.3.1
  1.3.6.1.4.1.1768.100.70.40.2.1.4.2  /home/me/scriptest/calls_BH  |
  or die;
  while (FH1) {
      print;
  }
  close FH1;

 Again, same problem. Don't use open to execute shell commands. Use system
 instead. In your case, you might wish to use backticks or open -| to trap
 the output of snmpget.

  The text in the file looks like this:

  2010-10-22 20:51
  SNMPv2-SMI::enterprises.1768.100.70.40.2.1.4.2 = Counter32: 132321

  I want it to look like this:

  2010-10-22 20:51 SNMPv2-SMI::enterprises.1768.100.70.40.2.1.4.2 =
  Counter32: 132321

 The easiest solution in your case would be to add the -n flag to echo, which
 will supress adding a newline. But you should revamp your script from the
 ground's up.



  Yeah i`m a total nub :)
  Can somone point me in the right direction here?

 Please see the resources athttp://perl-begin.org/to learn Perl properly.

 Regards,

         Shlomi Fish

 --
 -
 Shlomi Fish      http://www.shlomifish.org/
 Optimising Code for Speed -http://shlom.in/optimise

 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.

:)

Thanks for the help.
I think i`ll start again from scratch as you suggested.

I see my faults.. hehe



KAB


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




Print FH to file.

2010-10-23 Thread KA B
I`m trying to get the filehandler 1 and 2 to print the result in one
line.
The script i have made makes 2 lines.

The script goes like this:


my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
$year += 1900;
$mon += 1;
open FH,echo $year-$mon-$yday $hour:$min  /home/me/scriptest/
calls_BH |;
while (FH) {
print;
}
close FH;
open FH1, snmpget -v1 -c mee 1.2.3.1
1.3.6.1.4.1.1768.100.70.40.2.1.4.2  /home/me/scriptest/calls_BH  |
or die;
while (FH1) {
print;
}
close FH1;

The text in the file looks like this:

2010-10-22 20:51
SNMPv2-SMI::enterprises.1768.100.70.40.2.1.4.2 = Counter32: 132321

I want it to look like this:

2010-10-22 20:51 SNMPv2-SMI::enterprises.1768.100.70.40.2.1.4.2 =
Counter32: 132321


Yeah i`m a total nub :)
Can somone point me in the right direction here?


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




Re: Perl Threads

2010-10-14 Thread a b
Thanks a lot All of your

On Wed, Oct 13, 2010 at 6:21 AM, Brian Fraser frase...@gmail.com wrote:

 The usual elevator example:
 http://www.perl.com/pub/2002/09/04/threads.html

 I'm not entirely sure if the article is dated (I used it a couple of months
 back as a personal introduction to threads in general, for whatever that
 counts), but if anything, the explanation on building a threaded Perl, and
 the part about shared variables, are both still useful.


 Brian.



Re: Deleting last 10 lines of a file

2010-03-24 Thread sheela b
Thanks a lot Shlomi and Thomas.

I will try with these methods.


On Tue, Mar 23, 2010 at 7:13 PM, Shlomi Fish shlo...@iglu.org.il wrote:

 Hi Sheela,

 On Tuesday 23 Mar 2010 15:06:24 sheela b wrote:
  Hi All,
 
  How to delete last 10 lines of a file using Perl one liner?
 
  I used the following one liner to delete first 10 lines of a file,
 
  perl -i.bak -ne 'print unless 1..10' test.txt
 

 If it doesn't have to be a one-liner, you can do it efficiently using the
 following script:

 
 #!/usr/bin/perl

 use strict;
 use warnings;

 use File::ReadBackwards;
 use Getopt::Long;

 my $count;
 GetOptions(
n=i = \$count,
 );

 if (!defined($count))
 {
die Please specify -n for the line count.;
 }

 my $filename = shift;

 my $bw = File::ReadBackwards-new($filename)
or die Could not backwards-open '$filename' - $!;

 foreach my $idx (1 .. $count)
 {
$bw-readline();
 }

 my $wanted_len = $bw-tell();

 $bw-close();

 open my $truncate_fh, +, $filename
or die Could not truncate-open '$filename' - $!;

 truncate($truncate_fh, $wanted_len);

 close($truncate_fh);
 

 If you still insist on it being a one-liner, see:

 http://mail.perl.org.il/pipermail/perl/2005-August/007316.html

 You can do it as a one liner in a much less elegant way by using a cyclical
 queue, but I can't be bothered to implement it.

 Regards,

Shlomi Fish

 
  Regards
  Sheela

 --
 -
 Shlomi Fish   http://www.shlomifish.org/
 Parody on The Fountainhead - http://shlom.in/towtf

 Deletionists delete Wikipedia articles that they consider lame.
 Chuck Norris deletes deletionists whom he considers lame.

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



Deleting last 10 lines of a file

2010-03-23 Thread sheela b
Hi All,

How to delete last 10 lines of a file using Perl one liner?

I used the following one liner to delete first 10 lines of a file,

perl -i.bak -ne 'print unless 1..10' test.txt


Regards
Sheela


Re: evaluate for max and min value in array

2009-07-22 Thread sheela b
Hi Jenn,

You can fing max and min value as,

my @ar = (1,2,3,4,58,9,2,1);
my $max = (sort { $b = $a } @ar)[0];
my $min = (sort { $a = $b } @ar)[0];

Regards
Sheela
On Wed, Jul 22, 2009 at 12:48 PM, Jenn G. practicalp...@gmail.com wrote:

 Hello,

 How to lookup the max and min value in an array?
 Just like SQL's max() and min() functions.

 Thanks.

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





Authorize.net Error

2009-05-16 Thread sheela b
Hi All,

  I have shopping cart website integrating with authorize.net for Payment
gateway.
  Authorize.net is working fine in test mode, but in the live mode, i am not
able to give any credits to customer. It displays following error message.

The referenced transaction does not meet the criteria for issuing a
credit.

What may be the cause for this error?

Any help appreciated.

Regards
Sheela


very basic questions

2009-01-28 Thread b chen
i am completely new to perl, can you explain to me the following line of
code in red.

how does this line of code grab a time value and assign it to $ time,

how does assigment happend in this conditiona statement.



while ()
{
 chop;
 # Grab the time
 next unless ($time) = /(\d+:\d+:\d+\,\d+)/;


Need Help

2008-11-16 Thread a b
Hi ,
Can any body tells me what do we mean by below code
snip
$ROUTE::COMM{NEWROUTE}{OS()}
/snip

Thanks in Advance
a b .


Redirect option

2008-10-16 Thread sheela b
Is there any option to redirect a URL in perl other than Location ?

Regards

Sheela


fetching to docs using wget

2008-07-22 Thread a b
Hi,

I am trying to fetch various docs from server using wget. Below is the code
Files are downloading but of 0 size :(

Am i missing any thing

[EMAIL PROTECTED]:~/adave cat fetch.pl
open(S,./source.txt) || die Failed to open file 'source.txt' $!;
while(S)
{

if (/http/)
{
@a=split(/\//,$_);
$file=$a[-1];
$r=exec `/usr/bin/wget $_ ./$file `;
print $r;
print Printing the output of last $?;
exit;
}
}
close(S);
[EMAIL PROTECTED]:~/adave perl fetch.pl
--18:03:19--  http://localhost/training_files/docs/overview.ppt
   = `overview.ppt'
Resolving localhost... x.x.x.x.
Connecting to localhost x.x.x.x... connected.
HTTP request sent, awaiting response... 200 OK
Length: 145,920 [application/vnd.ms-powerpoint]

100%[==]
145,920   81.61K/s

18:03:21 (81.43 KB/s) - `overview.ppt' saved [145920/145920]

0Printing the output of last [EMAIL PROTECTED]:~/adave ls -l
total 5
-rw-r--r--  1 adave aix  254 2008-07-22 17:48 fetch.pl
-rw-r--r--  1 adave aix 4074 2008-07-22 16:52 source.txt
-rw-r--r--  1 adave aix0 2008-07-22 18:03 overview.ppt



Thanks,
a b


First perl program

2008-06-19 Thread Jason B
I'm really new to programming and this is my first perl prog.  I'm looking
for any advice or comments on this script.

(I don't want to develop bad habits from the start)

Thx.

#!/usr/bin/perl

#Name:circumf
#Date:Jun19/08
#Author:Bornhoft, J
#Purpose:to calculate the circumference of a circle

print Hi. I'm going to help you calculate the circumference of a circle\n;

$pi = 3.141592654;

print What is the radius of the circle?: ;
chomp($radius = STDIN);

if ($radius  0) {
$radius = 0;
print Psst...\nThe radius can\'t be less than zero.\nLet me help you
out there\n;
}

$diameter = ($radius * 2);
$area = ($pi * ($radius ** 2));
$circumf = ($diameter * $pi);

print  Radius: $radius\n Diameter: $diameter\n Area: $area\n And
finally!!!\n Circumference: $circumf\n;


problem runing code | strange Error

2007-10-23 Thread Juan B

-Hi,

Im trying to run this code: (im getting this error
message):

Can't use string (From) as a HASH ref while strict
refs in use at
/usr/lib/perl5/site_perl/5.8.8/Mail/Mailer.pm line
320.

The code:

use strict;
use warnings;
use Mail::Mailer;

my @lines = ();
open (INFO, /var/log/messages) or die $!;
while (my $line = INFO) {
   if ($line =~ /IDS/) {
  push @lines,$line;
   }
}
close INFO;
if (@lines) {
   my $mailer = Mail::Mailer-new(smtp,
10.83.27.71);
   $mailer-open( 'From' = 'Syslog
[EMAIL PROTECTED]',
  'To' = 'gabriela pinado
[EMAIL PROTECTED]',
  'Subject' = 'PiX Detected Attack '
);
   print $mailer @lines;
   $mailer-close or die can't close mailer: $!;
}

Any ideas where is the problem?

thanks a lot !

Juan


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

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




Re: problem runing code | strange Error

2007-10-23 Thread Juan B
Hi,

I did it and know I get another error:

syntax error at logcheck line 25, near 'PiX Detected
Attack } ' )
Missing right curly or square bracket at logcheck line
28, at end of line
Execution of logcheck aborted due to compilation
errors.

This is the code:

use strict;
use warnings;
use Mail::Mailer;

my @lines = ();
open (INFO, /var/log/messages) or die $!;
while (my $line = INFO) {
   if ($line =~ /IDS/) {
  push @lines,$line;
   }
}
close INFO;
if (@lines) {
   my $mailer = Mail::Mailer-new(smtp,
10.83.27.71);
  $mailer-open( {'From' = 'Syslog
[EMAIL PROTECTED]',
  'To' = 'gabriela pinado
[EMAIL PROTECTED]',
  'Subject' = 'PiX Detected Attack }
' );
   print $mailer @lines;
   $mailer-close or die can't close mailer: $!;


thanks a lot !

Juan


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

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




Re: problem runing code | strange Error

2007-10-23 Thread Juan B
Ok I did it and know I get another error :-(
here goes the error:
 Died at /usr/lib/perl5/site_perl/5.8.8/Mail/Mailer.pm
line 284.



this is the code:
use strict;
use warnings;
use Mail::Mailer;

my @lines = ();
open (INFO, /var/log/messages) or die $!;
while (my $line = INFO) {
   if ($line =~ /IDS/) {
  push @lines,$line;
   }
}
close INFO;
if (@lines) {
   my $mailer = Mail::Mailer-new(smtp,
10.83.27.71);
  $mailer-open({
'From' = 'Syslog [EMAIL PROTECTED]',
'To' = 'gabriela pinado
[EMAIL PROTECTED]',
'Subject' = 'PiX Detected Attack'
});
   print $mailer @lines;
   $mailer-close or die can't close mailer: $!;
}
~

please assist!

thanks very much !

Juan


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

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




help with reading file script | Help !!

2007-10-19 Thread Juan B
Hi all !!

im really new to perl so please bare with me and
help..

I need a script to read /var/log messages and each
time it sees a line with the word IDS it will send
the whole line via mail to the administrator of the
IDS, here is an example of such a line:
Oct 19 15:40:30 172.31.0.254 %PIX-4-400011: IDS:2001
ICMP unreachable from 200.69.22.146 to 200.61.54.55 on
interface outside

I wrote this script:

#!/usr/local/bin/perl

$file = '/var/log/messages';  # Name the file
open(INFO, /var/log/messages);   # Open the file

while
$message = INFO / IDS/g {# Read it
into an array
 $ message = $


 sub sendEmail # simple Email function

 my $sendmail = '/usr/lib/sendmail';
 open(MAIL, |$sendmail -oi -t);
 print MAIL From: [EMAIL PROTECTED];
 print MAIL To: [EMAIL PROTECTED];
 print MAIL Subject: Pix IPS Attck Detection\n\n;
 print MAIL $message\n;
 close(MAIL);
 }

It doesnt work and I dont know why... can someone
help?

another question, how to execute this script so it
will be in memory oc the server all the time? should I
run it throw rc.local? 

thanks a lot for helping me !!

thanks !

Juan


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

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




Re: Net::Telnet --help required

2007-05-17 Thread a b

Hi Jay,

Thanks for your resoponse. I tried with the suggested but it failed due to
timed out
snip(j.pl)
use Net::Telnet;
my $t = new Net::Telnet;
$t-open(slias10);
print($t-waitfor('/login:.*$/'));
$t-print(root);
sleep(2);
@forecast=$t-cmd(/usr/bin/ls);
print @forecast;
/snip
OP
C:\perl j.pl

HP-UX slias10 B.11.31 U ia64 (ta)

command timed-out at j.pl line 7
login:
/OP

Please, suggest i am able to see the

On 5/16/07, Jay Savage [EMAIL PROTECTED] wrote:


On 5/16/07, a b [EMAIL PROTECTED] wrote:
 Hello,
 I am trying to telnet to all m/c for which i haven't set password(only
root
 is a valid user)
 any body can telnet using root user
 But when i try to access through perl it
 snip
 use warnings;
 use Net::Telnet;

 my $t = new Net::Telnet (Timeout = 10,Prompt = '/bash\$ $/');
 my @line;
 $t-open(host1);
 $t-waitfor('/login:.*$/');
 $t-print(root);
 $forecast=$t-print(/usr/bin/ls);
 print $forecast;


 O/P : 1

 OR

 use warnings;
 use Net::Ping;
 use Net::Telnet;

 my $t = new Net::Telnet (Timeout = 10,Prompt = '/bash\$ $/');
 my @line;
 $t-open(host1);
 $t-login(root,);
 $result=$t-cmd(/usr/bin/ls);
 print $result;

 O/P : timed-out waiting for password prompt at j.pl line 8



Close.

You do the login correctly in example 1, but then you use print to
issue the command. all that does is print the string /usr/bin/ls\n
to the remote terminal and return 1 to let you know the command
succeeded. If you want the output of the remote command, you need to
use cmd (in list context)

In example 2, you don't pass a password to login or waitfor one, so
you never login. You do, though, use cmd, which is what you want,
although you need list context:

$t-open(host1);
$t-waitfor('/login:.*$/');
$t-print(root);
my @forecast=$t-cmd(/usr/bin/ls);
my $scalar_forecast = join , @forecast;
# or join'\n', I don't remember if cmd returns newlines or not

HTH,

-- jay
--
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!



Net::Telnet --help required

2007-05-16 Thread a b

Hello,
I am trying to telnet to all m/c for which i haven't set password(only root
is a valid user)
any body can telnet using root user
But when i try to access through perl it
snip
use warnings;
use Net::Telnet;

my $t = new Net::Telnet (Timeout = 10,Prompt = '/bash\$ $/');
my @line;
$t-open(host1);
$t-waitfor('/login:.*$/');
$t-print(root);
$forecast=$t-print(/usr/bin/ls);
print $forecast;


O/P : 1

OR

use warnings;
use Net::Ping;
use Net::Telnet;

my $t = new Net::Telnet (Timeout = 10,Prompt = '/bash\$ $/');
my @line;
$t-open(host1);
$t-login(root,);
$result=$t-cmd(/usr/bin/ls);
print $result;

O/P : timed-out waiting for password prompt at j.pl line 8


Please, help me to understand the solution of it.
I need this as urgent requirement for house-keeping activities

Thanks in adavance

_abhi


module installation problem

2007-04-24 Thread I . B .

Hi people,

I installed module Net::Ftp::Recursive. All following steps succeeded:
perl Makefile.PL
make
make test
make install

# next i tested if module loading correctly
~$ perl -MNet::Ftp::Recursive -e 1;
Can't locate Net/Ftp/Recursive.pm in @INC (@INC contains: /etc/perl
/usr/local/lib/perl/5.8.7 /usr/local/share/perl/5.8.7 /usr/lib/perl5
/usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8
/usr/local/lib/site_perl .).
BEGIN failed--compilation aborted.

# it exists
$ ls /usr/local/share/perl/5.8.7/Net/FTP/Recursive.pm
/usr/local/share/perl/5.8.7/Net/FTP/Recursive.pm

# cd to perl libs
$ cd /usr/local/share/perl/5.8.7

# run ok!
$ perl -MNet::FTP::Recursive -e 1;

# go back to $HOME
$ cd ~

# run ok!
$ perl -MNet::FTP::Recursive -e 1;

Does anyone know if this is some kind of cache I am not aware about?
thank you in advance.

~igy

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




Re: module installation problem

2007-04-24 Thread I . B .

I will try to reproduce this again. I am sure it was Net::FTP::Recursive

thank you for response

~igy



On 4/24/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

Hi,

I think that you have a little mistake
Run perl -MNet::FTP::Recursive -e 1; instead of perl -MNet::Ftp::Recursive -e 
1;.

Yours,
Yaron Kahanovitch
- Original Message -
From: I.B. [EMAIL PROTECTED]
To: beginners@perl.org
Sent: Wednesday, April 25, 2007 7:27:18 AM (GMT+0200) Auto-Detected
Subject: module installation problem

Hi people,

I installed module Net::Ftp::Recursive. All following steps succeeded:
perl Makefile.PL
make
make test
make install

# next i tested if module loading correctly
~$ perl -MNet::Ftp::Recursive -e 1;
Can't locate Net/Ftp/Recursive.pm in @INC (@INC contains: /etc/perl
/usr/local/lib/perl/5.8.7 /usr/local/share/perl/5.8.7 /usr/lib/perl5
/usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8
/usr/local/lib/site_perl .).
BEGIN failed--compilation aborted.

# it exists
$ ls /usr/local/share/perl/5.8.7/Net/FTP/Recursive.pm
/usr/local/share/perl/5.8.7/Net/FTP/Recursive.pm

# cd to perl libs
$ cd /usr/local/share/perl/5.8.7

# run ok!
$ perl -MNet::FTP::Recursive -e 1;

# go back to $HOME
$ cd ~

# run ok!
$ perl -MNet::FTP::Recursive -e 1;

Does anyone know if this is some kind of cache I am not aware about?
thank you in advance.

~igy

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






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




RE: sending output to file and terminal (in Unix use tee)

2007-03-29 Thread Tilley, Matthew B
If you are on a Unix platform, you can use tee in your script to
direct output to two places at the same time. 

- Matt

-Original Message-
From: John W. Krahn [mailto:[EMAIL PROTECTED] 
Sent: Thursday, March 29, 2007 2:17 AM
To: Perl Beginners
Subject: Re: sending output to file and terminal

lakshmi priya wrote:
 Hi all,

Hello,

 I have written a perl script that prints the output to the 
 terminal. I also want to write the  output to a file. So, what I have 
 done is write the output to a file and then print the file. I was just

 wondering if there any way to write to both - terminal and file at the
same time?

perldoc -q How do I print to more than one file at once




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

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



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




Re: Alternative lookaheads in substitution, is it possible? (SOLVED!!!)

2007-01-20 Thread I . B .

one more to remove spaces selectively:

$string =~ s/(\s+)(?:(?!date=|time=)(?=\w+=))/*/g;

cheers,
~i


On 1/20/07, Mumia W. [EMAIL PROTECTED] wrote:

On 01/20/2007 06:46 AM, Michael Alipio wrote:
 Cool

 I got this from approximately 71% perldoc perlre:

  print 5: got $1\n if $x =~ /^(\D*)(?=\d)(?!123)/;

 so I don't need || between multiple look ahead assertions...

 Sometimes, it's more rewarding to solve you're problem on your own.
 You just have to RTFM.. :-)

 More power to this helpful commmunity!!



Well if you like that, you're going to love this:

use strict;
use warnings;

my $string = 'Jan 19 11:37:21 firewall date=2007-01-19 time=11:42:15
devname=TESTfirewall device_id=FGT-602905503304 log_id=0104032006
type=event subtype=admin pri=information vd=root user=admin
ui=GUI(192.168.1.1) action=login status=success reason=none
msg=User admin login successfully from GUI(192.168.1.1)';

my %hash = $string =~ /(\w+)=([^]+|\S+)/g;
s/^()(.+)\1$/$2/ for (values %hash);

local $\ = \n;
print log_id = $hash{log_id};
print msg = $hash{msg};
print ui = $hash{ui};



:-)





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





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




Re: Selective splits... (treat this pattern as a delimiter only if it is followed by this pattern)

2007-01-19 Thread I . B .

you can use lookaheads:

my @matched = split /\s+(?=\w+=)/,$string;

cheers,
~i

On 1/19/07, Michael Alipio [EMAIL PROTECTED] wrote:

Hi,

Suppose I have:


my $string = 'Jan 19 11:37:21 firewall date=2007-01-19 time=11:42:15 
devname=TESTfirewall device_id=FGT-602905503304 log_id=0104032006 ty
pe=event subtype=admin pri=information vd=root user=admin ui=GUI(192.168.1.1) 
action=login status=success reason=none msg
=User admin login successfully from GUI(192.168.1.1)
';


That is, on a regular \s+ split, I will produce this list of strings:
Jan
19
11:37:21
firewall
date=2007-01-19
time=11:42:15
devname=TESTfirewall
device_id=FGT-602905503304
log_id=0104032006
type=event
subtype=admin
pri=information
vd=root
user=admin
ui=GUI(192.168.1.1)
action=login
status=success
reason=none
msg=User
admin
login
successfully
from
GUI(192.168.1.1)

However, I only want to split it with \s+ as delimiter, only if that \s+ is followed by 
\w+= so that the: 'msg=User admin login successfully from GUI(192.168.1.1) 
will not be splited.

I tried putting parenthesis in my split pattern:

split/(\s+)\w+=/, $_

So that it will only split the line delimited by space if it is followed by any 
\w+= just like when doing a regexp matching.
But the program treats \w+= as part of the whole pattern so instead of getting:

date=2007-01-19

time=11:42:15

devname=TESTfirewall

device_id=FGT-602905503304


I got:

2007-01-19

11:42:15

TESTfirewall

FGT-602905503304


Any idea how to accomplish my goal?










It's here! Your new message!
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/



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




Re: character classes vs regexp alternatives (using ( ) or [ ]

2007-01-19 Thread I . B .

[,|\s+] - means one of the following characters: , or | or \s or +

(,|\s+) - means , or \s+

, but yeas alternation will match $2 in :

~ /date=(\S+?)(\s+|,)/;



On 1/19/07, Michael Alipio [EMAIL PROTECTED] wrote:

Hi,

I'm a bit confused here:

I have a regexp:

($date) = $log =~ /date=(\S+?)[\s+|,]/;

so if I have:

date=2007-01-12 blah blah

or

date=2007-01-12,blah,blah

I was able to retrieve 2007-01-12

However, just recently after reading my notes on perl, I read that I should use 
parenthesis on regexp alternatives.

so this:

[\s+|,]

should be written as

(\s+|)

But if I use that parenthesis my regexp:

($date) = $log =~ /date=(\S+?)[\s+|,]/;

As I remember my regexp notes, If I want to match something, I will have to put it inside parenthesis. And if 
I change those [ ] into ( ) I'm afraid that I might also match those \s+ or 
,


Can you shed some light on this?

Thanks.












TV dinner still cooling?
Check out Tonight's Picks on Yahoo! TV.
http://tv.yahoo.com/



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




Re: Selective splits... (treat this pattern as a delimiter only if it is followed by this pattern)

2007-01-19 Thread I . B .

substitute \s with * to make split easier sounds like a very bad idea.
didn't see people doing that in perl.
problem is solved, why do you add extra complexity?

On 1/19/07, Michael Alipio [EMAIL PROTECTED] wrote:




- Original Message 
From: I.B. [EMAIL PROTECTED]
To: begginers perl.org beginners@perl.org
Sent: Saturday, January 20, 2007 1:02:39 PM
Subject: Re: Selective splits... (treat this pattern as a delimiter only
if it is followed by this pattern)

 you can use lookaheads:

 my @matched = split /\s+(?=\w+=)/,$string;

I've already figured that out, but there's one problem  I encountered:
What I did was to modify the entire line first and substitute all necessary
\s+. with '*' so that splitting will be easier.

Those \s+ were:

all spaces if the following word is not either date or time and also all
spaces if the following word is \w+=

My regexp looks like this:

$_ =~ s/\s+(?!(date|time))/*/g ;

Now, having a problem where to put my parenthesis to add the ?=\w+=
condition..
Can you help me with this? I tried several times but I failed.

Thanks.






 cheers,
 ~i

On 1/19/07, Michael Alipio [EMAIL PROTECTED] wrote:
 Hi,

 Suppose I have:


 my $string = 'Jan 19 11:37:21 firewall date=2007-01-19 time=11:42:15
devname=TESTfirewall device_id=FGT-602905503304 log_id=0104032006 ty
 pe=event subtype=admin pri=information vd=root user=admin
ui=GUI(192.168.1.1) action=login status=success reason=none msg
 =User admin login successfully from GUI(192.168.1.1)
 ';


 That is, on a regular \s+ split, I will produce this list of strings:
 Jan
 19
 11:37:21
 firewall
 date=2007-01-19
 time=11:42:15
 devname=TESTfirewall
 device_id=FGT-602905503304
 log_id=0104032006
 type=event
 subtype=admin
 pri=information
 vd=root
 user=admin
 ui=GUI(192.168.1.1)
 action=login
 status=success
 reason=none
 msg=User
 admin
 login
 successfully
 from
 GUI(192.168.1.1)

 However, I only want to split it with \s+ as delimiter, only if that \s+
is followed by \w+= so that the: 'msg=User admin login successfully from
GUI(192.168.1.1) will not be splited.

 I tried putting parenthesis in my split pattern:

 split/(\s+)\w+=/, $_

 So that it will only split the line delimited by space if it is followed
by any \w+= just like when doing a regexp matching.
 But the program treats \w+= as part of the whole pattern so instead of
getting:

 date=2007-01-19

 time=11:42:15

 devname=TESTfirewall

 device_id=FGT-602905503304


 I got:

 2007-01-19

 11:42:15

 TESTfirewall

 FGT-602905503304


 Any idea how to accomplish my goal?











 It's here! Your new message!
 Get new email alerts with the free Yahoo! Toolbar.
 http://tools.search.yahoo.com/toolbar/features/mail/


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




 
No need to miss a message. Get email on-the-go
with Yahoo! Mail for Mobile. Get started.


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




Re: simple perl script on Windows

2007-01-18 Thread I . B .

also keep open and close outside the loop.
you overwriting previously written lines.

open FILE2,$file;
foreach @lines
{
print FILE2 $_;
}
close FILE2

cheers

On 1/18/07, Mathew [EMAIL PROTECTED] wrote:

Thanks.  That likely will help.  However, I still can't even get it to
perform any action.  I have it set to print to the screen right now but
it isn't creating any output.

Mathew

Guerrero, Citlali (GE, Corporate, consultant) wrote:
 Hi Mathew :

 This is what your regexp ($line =~ s/^.*\s//g;)means :  Remove any
 kind of character follow by ONE SPACE at the BEGINNING  of the string,
 and you are right it do not do what you want.
 If I understand right what you want to do is preserve the name of
 the subfolder, if that is correct then you may need this regexp:

   $line =~ s/.*[\s+\t+](\w+)/$1/

 this regexp does : Remove any character follow by : one or more spaces
 or one or more tabs, follow by one or more words(check the perldoc if
 you do not know the meaning of  \w) and all this patron replace it with
 $1 which is the (\w+) and should be(according to your example) =A
 Perfect Circle

 I hope it help =D
 But if you have any questions I kindly suggest you to take a look at  :

 http://www.troubleshooters.com/codecorn/littperl/perlreg.htm
 or
 http://www.perl.com/doc/manual/html/pod/perlre.html

 Cheers
 Mathew escribió:
 I have a file with a list of subfolders.  The list was created using dir
 and each entry is like thus:

 12/12/2005  04:38 AMDIR  A Perfect Circle

 I then created a simple script that I hoped would eliminate everything
 prior to the last bit of text which follows the big space.

 open FILE, H:\My Music\folderlist.txt;

 foreach my $line (readline FILE) {
 $line =~ s/^.*\s//g;
 open FILE2, H:\My Music\artists.txt;
 print FILE2 $line . \n;
 close FILE2;
 }

 close FILE;

 Not only do I think the regex is very wrong, but it isn't doing
 anything.  If I had to guess, it is saying to replacy everything up to
 the first space with nothing.  While this isn't what I want it to do,
 having it do that would probably be a good step in the right direction.
  However, it won't even do that.

 What am I doing wrong here?

 Mathew









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





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




Re: reg exp continued need pulled from reference

2006-12-13 Thread Derek B. Smith
--- Lawrence Statton XE2/N1GAK [EMAIL PROTECTED]
wrote:
 If you're dealing with variable length strings,
 separated by some kind
 of character, then regexp is the tool you want, not
 substr.
 
 This snippet will work so long as hostname and
 platform name are made
 up of \w ... if not, substitute in an appropriate
 character class.
 
 #!/usr/bin/perl
 use strict;
 use warnings;
 
 foreach my $filename (qw (
  /home/dbsmith/passwd.dubhpr01.sun
  /some/other/path/passwd.fizzbox.hpux
  /yet/another/path/passwd.gronko.aix
  /still/more/paths/to/passwd.foohost.linux
   )
) {
   my ($hostname, $platform) = $filename =~
 m|\.(\w+)\.(\w+)$|;
   print Hostname: $hostname, Platform:
 $platform\n;
 }


I am using Spreadsheet::WriteExcel to populate certain
columns which is working, but in column A for example
I am using the method write_col which requires a
reference, I am printing the absolute path
/home/dbsmith/passwd.dubhpr01.sun when all I need to
print is sun and in column B all I will need is
dubhpr01 or the hostname.  For this reason I am trying
to use a regexp to grab $1 and $2 or sun and dubhpr01 
then use write_col method.  This is not working and in
my test code I want to know what data structure to
use.


use strict;
use warnings;
use Data::Dumper;
my $string = qw(/home/dbsmith/passwd.dubhpr01.sun);
my ($host,@OS) = $string =~ m|\.(\w+\d+)\.(\w+)$|i;
my $aref = \$host;
my $aref2 = [EMAIL PROTECTED];

#print $1,\n;
#print $2,\n;
if (ref ($aref) eq SCALAR) {
   print yes\n;
}
print newline\n;

if (ref ($aref2) eq ARRAY) {
   print YES\n;
}
print ${$aref},\n;
print @{$aref2}[0],\n;

__OUTPUT__

yes
newline
YES
dubhpr01
sun

so my question 1 is what is @{$aref2}[0] and
why isn't write_col writing its data from my code
below:

##-- Write data from ref and format cells A2 and down
--##

my $string = qw(/home/dbsmith/passwd.dubhpr01.sun);
my @host   = $string =~ m|\.(\w+\d+)$|i;
my $aref   = [EMAIL PROTECTED];

print @{$aref},\n;
if (ref ($aref) eq ARRAY) {
print YES\n;
$worksheet-write_col('A2',$aref,$sheet_format);
}

I then tried 

$worksheet-write_col('A2',@{$aref},$sheet_format);

and I get error:

Not an array ref in call to write_row()No such file or
directory at uid_check.pl line 121
main::__ANON__('Not an array ref in call to
write_row()No such file or direct...') called at
/opt/perl/lib/5.8.2/Carp.pm line 191
Carp::croak('Not an array ref in call to
write_row()No such file or directory') called at
/opt/perl/lib/site_perl/5.8.2/Spreadsheet/WriteExcel/Worksheet.pm
line 1354
   
Spreadsheet::WriteExcel::Worksheet::write_col(1,0,'Spreadsheet::WriteExcel::Format=HASH(0x40610804)')
called at uid_check.pl line 121


thank you
derek

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




Re: reg exp continued need pulled from reference

2006-12-13 Thread Derek B. Smith
--- Lawrence Statton XE2/N1GAK [EMAIL PROTECTED]
wrote:

  --- Lawrence Statton XE2/N1GAK
 [EMAIL PROTECTED]
  I am using Spreadsheet::WriteExcel to populate
 certain
  columns which is working, but in column A for
 example
  I am using the method write_col which requires a
  reference,
 
 
 Not just a reference but an ARRAY reference for
 all the values that
 will go into that column (or a reference to an array
 of arrayrefs to
 write a rectangular area in one shot).  The example
 about a fifth of
 the way through the Spreadsheet::WriteExcel pod
 shows it pretty clearly.
 
  I am printing the absolute path
  /home/dbsmith/passwd.dubhpr01.sun when all I need
 to
  print is sun and in column B all I will need is
  dubhpr01 or the hostname.  
 
 So stop printing what you don't need, and start
 printing what you do
 need :) :) :)  This code is not writing itself --
 you have to take a
 smidgeon of responsibility for its output.  
 
 
  For this reason I am trying
  to use a regexp to grab $1 and $2 or sun and
 dubhpr01 
  then use write_col method.  This is not working
 and in
  my test code I want to know what data structure to
  use.
  
 
 Are you sure that write_col is the method you want
 to use in this
 case?
 
  use strict;
  use warnings;
  use Data::Dumper;
  my $string =
 qw(/home/dbsmith/passwd.dubhpr01.sun);
  my ($host,@OS) = $string =~
 m|\.(\w+\d+)\.(\w+)$|i;
  my $aref = \$host;
  my $aref2 = [EMAIL PROTECTED];
 
 Slow down a bit -- think about what you are writing.
  I don't want to
 seem bitchy, but you often post code that looks like
 you just keep
 throwing code into the file willy-nilly trying to
 see what sticks.
 This code CLEARLY has that feel.
 
  
  #print $1,\n;
  #print $2,\n;
  if (ref ($aref) eq SCALAR) {
 print yes\n;
  }
  print newline\n;
  
  if (ref ($aref2) eq ARRAY) {
 print YES\n;
  }
  print ${$aref},\n;
  print @{$aref2}[0],\n;
  
  __OUTPUT__
  
  yes
  newline
  YES
  dubhpr01
  sun
  
  so my question 1 is what is @{$aref2}[0] and
 
 $aref2 is[ 'sun' ]
 @{$aref2} is ( 'sun' )
 @{$aref2}[0] is  'sun'
 
 
 Perhaps the reason you find yourself getting
 confusing output is your
 confusing variablenames. aref2 says nothing about
 the data it
 contains, and is dangerously similar to aref.  If
 you are debugging
 something, you are going to see what SHOULD be there
 instead of what
 IS there.
 
  why isn't write_col writing its data from my code
  below:
  
  ##-- Write data from ref and format cells A2 and
 down
  --##
  
  my $string =
 qw(/home/dbsmith/passwd.dubhpr01.sun);
  my @host   = $string =~ m|\.(\w+\d+)$|i;
  my $aref   = [EMAIL PROTECTED];
 
  print @{$aref},\n;
  if (ref ($aref) eq ARRAY) {
  print YES\n;
 
 $worksheet-write_col('A2',$aref,$sheet_format);
  }
 
 It worked for me.  (Outside of the fact I had to
 redact the
 $sheet_format because you didn't post a complete
 runnable program.)
 
  
  I then tried 
  
 
 $worksheet-write_col('A2',@{$aref},$sheet_format);
  
  and I get error:
  [error redacted]
 
 Well, the documentation pretty clearly calls for an
 arrayref in the
 second argument to write_col, so I have no idea why
 you tried passing
 in an array.
 
  
  
  thank you
  derek
  
 


I know its an ARRAY reference why u think I wrote eq
ARRAY.

I am not 100% sure write_col is the method I need,
that is why I post emails to this list, but I need to
write data in each respective column so using
write_col seems logical.

Sorry u think that, but I do think about what I write
and how to get to my end goal and yes you do sound
bitchy and rude! My apoligies I am not a Perl know it
all but this list is for posting questions so why do
people like u have to make things more difficult by
being negative?

yes the code I provided with the OUTPUT was only test
code or as u state it willy nilly. I did not want to
post all 186 lines so I took out what is not working
which is know as a snippett.

If you seem to have all the Perl knowledge then get
this code working and send me the output BECAUSE IT IS
NOT WORKING FOR ME!


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




RE: reg exp continued need pulled from reference

2006-12-13 Thread Derek B. Smith
--- Charles K. Clarkson [EMAIL PROTECTED]
wrote:

 Derek B. Smith mailto:[EMAIL PROTECTED]
 wrote:
 
 
 : I then tried
 
 Try something simpler, not more complex. Test
 this case.
 
 my @hosts = ( 'sun' );
 $worksheet-write_col( 'A2', [EMAIL PROTECTED], $sheet_format
 );
 
 
 If it fails testing then there may be a problem
 with
 write_col() or with the setup for the object
 $worksheet.
 
 If it does test okay then the problem may be in
 the
 data manipulation just before the call to
 write_col().
 
 
 
 HTH,
 
 Charles K. Clarkson
 -- 

that worked, thank you...will keep trying.


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




reg exp continued need pulled from reference

2006-12-13 Thread Derek B. Smith
I want to extend any apologies necessary for my last
post.  I am not a violent person its just I get
annoyed when some people are negative, or to me, are
condescending.  I was not mad just upset and bothered.
No biggy and the past is in the past. : )

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




reg exp

2006-12-12 Thread Derek B. Smith
I have a string like so:

/home/dbsmith/passwd.oftappp1.hpux and I need to parse
out oftappp1 and hpux.

I have tried to use substr and and regexp with =~.
Here is what I have tried, but need some help cause I
am getting frustrated.

NOTE: strings after passwd are variable in length,
could be 3-10 characters long.

use strict;
use warnings;
my $string = qw(/home/dbsmith/passwd.dubhpr01.sun);
#my ($host_name) = $string =~ /\.\w+\.\w+/g;
my ($host) = substr ($string,21);
my ($OS) = substr ($string,-3);


The OS variable outputs 'sun' but obviously will not
work for hpux or linux.

And the host variable outputs 'dubhpr01.sun' when all
I need is 'dubhpr01' 

thank you
derek

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




Re: reg exp

2006-12-12 Thread I . B .

or just:
my $filename=/home/dbsmith/passwd.duby02.linux;
my ($pass,$hostname,$platform)=split /\./, $filename;

~i


On 12/12/06, Lawrence Statton XE2/N1GAK [EMAIL PROTECTED] wrote:



If you're dealing with variable length strings, separated by some kind
of character, then regexp is the tool you want, not substr.

This snippet will work so long as hostname and platformname are made
up of \w ... if not, substitute in an appropriate character class.

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

foreach my $filename (qw (
   /home/dbsmith/passwd.dubhpr01.sun
   /some/other/path/passwd.fizzbox.hpux
   /yet/another/path/passwd.gronko.aix
   /still/more/paths/to/passwd.foohost.linux
)
 ) {
  my ($hostname, $platform) = $filename =~ m|\.(\w+)\.(\w+)$|;
  print Hostname: $hostname, Platform: $platform\n;
}


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





Re: reg exp

2006-12-12 Thread Derek B. Smith

--- D. Bolliger [EMAIL PROTECTED] wrote:

 Derek B. Smith am Dienstag, 12. Dezember 2006 23:19:
  I have a string like so:
 
  /home/dbsmith/passwd.oftappp1.hpux and I need to
 parse
  out oftappp1 and hpux.
 
  I have tried to use substr and and regexp with =~.
  Here is what I have tried, but need some help
 cause I
  am getting frustrated.
 
  NOTE: strings after passwd are variable in length,
  could be 3-10 characters long.
 
  use strict;
  use warnings;
  my $string =
 qw(/home/dbsmith/passwd.dubhpr01.sun);
  #my ($host_name) = $string =~ /\.\w+\.\w+/g;
 [snipped]
 
 my ($offtap1,

$hpux)='/home/dbsmith/passwd.dubhpr01.sun'=~/\.(\w+)\.(\w+)\Z/;
 
 More general help for all sorts of regex tasks is
 provided by perldoc perlre.
 
 Dani
 

Ah...yes I was thinking of using $1 and $2...cant
beleive I forgot.  Thanks though!

And Lawrence thank you for the tip: If you're dealing
with variable length strings, separated by some kind
of character, then regexp is the tool you want, not
substr.


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




return 1

2006-12-08 Thread Derek B. Smith
Why is return 1 coded at the end of many programs. For
example:

I know it means true but what does this do and why?
thank you
derek


#!/usr/bin/perl
#use strict;
my $user_name = qq(dsmithxx);
my $user_password = qq();
my $sql_server = qq(x);
my ($dbh,$drh,$stmt);
local ($whichmethod,$forminfo,%FORM_DATA);
use DBI;

sub initialize_dbi {
  $drh = DBI-install_driver('mysql');
  $dbh =
DBI-connect(DBI:mysql:$user_name:$sql_server,
$user_name, $user_password) or die did not
connect to DBI: $!;
}

sub run_statement {
  $stmt = $_[0];
  $sth = $dbh-prepare($stmt);
  $sth-execute;
}

sub parse_input {
 $whichmethod = $ENV{'REQUEST_METHOD'};
 ($forminfo,%FORM_DATA);
if($whichmethod eq GET){ 
$forminfo = $ENV{QUERY_STRING};
  }else{
$forminfo = STDIN; 
  } 

my @key_value_pairs = split(//,$forminfo); 
foreach my $pair (@key_value_pairs){

   my ($key,$value) = split(/=/,$pair);
 $value =~ s/\+/ /g; 
 $value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack(C,
hex($1))/eg;
 $value =~ s/'/\\'/g;
 $FORM_DATA{$key} = $value;
  }
} 
sub print_header {
   print Content-type: text/html \n\n; 
}
return 1;


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




Re: return 1

2006-12-08 Thread Derek B. Smith
--- Jay Savage [EMAIL PROTECTED] wrote:

 On 12/8/06, Derek B. Smith
 [EMAIL PROTECTED] wrote:
  Why is return 1 coded at the end of many programs.
 For
  example:
 
  I know it means true but what does this do and
 why?
 
 Derek,
 
 For historical reasons, the final statement of any
 script that is
 imported with use or require (and possibly do?) must
 return true so
 that the compiler knows the module has (in theory)
 been imported
 properly.
 
 'return1;' or more frequently just '1;' has become
 the norm because
 it's simple, easy, and clear. At this point it's
 almost an article of
 faith. In theory, though, any true value would
 suffice.
 
 HTH,
 

ok understood. thanks Jay and Jeff.


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




Re: Perl Query - Conversion of EXE file

2006-12-07 Thread Derek B. Smith
   The input for the EXE has to be taken from the
 file provided by the
   user.AndThe EXE shud get invoked by just
 dragging and dropping the
   input file on the EXE.
  
   Assume, the input file is some text file
 containing some raw data.
  
   How should this be done?
 
  You'll get the path to the dropped file in @ARGV.
 
  Jenda
  = [EMAIL PROTECTED] ===
 http://Jenda.Krynicky.cz =
  When it comes to wine, women and song, wizards are
 allowed
  to get drunk and croon as much as they like.
  -- Terry Pratchett in Sourcery
 
 
 
 Hi,
 
 I also wanted to tell the same. For drag and drop,
 the filename is read from
 $ARGV[0].
 
 Now, my tool's EXE is working.
 
 
 Thanks a lot for your constant support.
 
 Thanks and Regards,
 Dharshana
 

Dharshana, 

was wondering if you would be so kind to provide a
summary of you problem and solution since its been
such a long email thread? Code snippets would be cool
too!

thank you
derek


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




Fwd: failure notice

2006-12-06 Thread Derek B. Smith
Is there anyway this address can be corrected or
removed from the list? I have seen this once before
but it has been some time ago.

: ? )





Note: forwarded message attached.---BeginMessage---
Hi. This is the qmail-send program at la.mx.develooper.com.
I'm afraid I wasn't able to deliver your message to the following addresses.
This is a permanent error; I've given up. Sorry it didn't work out.

beginners@perl.org:
This message is looping: it already has my Delivered-To line. (#5.4.6)

--- Below this line is a copy of the message.

Return-Path: [EMAIL PROTECTED]
Received: (qmail 24226 invoked by alias); 6 Dec 2006 21:54:51 -
X-Spam-Status: No, hits=0.8 required=8.0

tests=BAYES_00,DK_POLICY_SIGNSOME,DK_POLICY_TESTING,DK_SIGNED,DNS_FROM_RFC_ABUSE,DNS_FROM_RFC_POST,DNS_FROM_RFC_WHOIS,UNPARSEABLE_RELAY
X-Spam-Check-By: la.mx.develooper.com
Received-SPF: neutral (x1.develooper.com: local policy)
Received: from mailgate2.darpa.mil (HELO mailgate2.darpa.mil) (192.5.18.62)
by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Wed, 06 Dec 2006 
13:54:40 -0800
Received: from sde2k3-mx2.darpa.mil (ws1-73.darpa.mil [158.63.1.73])
by mailgate2.darpa.mil (8.13.6/8.12.8) with ESMTP id kB6LsRr7029612
for beginners@perl.org; Wed, 6 Dec 2006 16:54:27 -0500 (EST)
Received: from mail pickup service by sde2k3-mbt.darpa.mil with Microsoft 
SMTPSVC; Wed, 6 Dec 2006 16:53:43 -0500
Received: from lists.develooper.com (x6.develooper.com [63.251.223.186])by 
mailgate1.darpa.mil (8.13.6/8.12.8) with SMTP id kB5M2kQ9011790for 
[EMAIL PROTECTED]; Tue, 5 Dec 2006 17:02:47 -0500 (EST)
Received: (qmail 10579 invoked by uid 514); 5 Dec 2006 22:02:45 -
Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
Precedence: bulk
List-Post: mailto:beginners@perl.org
List-Help: mailto:[EMAIL PROTECTED]
List-Unsubscribe: mailto:[EMAIL PROTECTED]
List-Subscribe: mailto:[EMAIL PROTECTED]
List-Id: beginners.perl.org
Delivered-To: mailing list beginners@perl.org
Received: (qmail 10570 invoked from network); 5 Dec 2006 22:02:44 -
Received: from x1a.develooper.com (HELO x1.develooper.com) (216.52.237.111) 
by lists.develooper.com with SMTP; 5 Dec 2006 22:02:44 -
Received: (qmail 28543 invoked by uid 225); 5 Dec 2006 22:02:44 -
Delivered-To: beginners@perl.org
Received: (qmail 28528 invoked by alias); 5 Dec 2006 22:02:42 -
Received-SPF: pass (x1.develooper.com: local policy)
Received: from web42403.mail.scd.yahoo.com (HELO 
web42403.mail.scd.yahoo.com) (66.218.93.226)   by la.mx.develooper.com 
(qpsmtpd/0.28) with SMTP; Tue, 05 Dec 2006 14:02:39 -0800
Received: (qmail 33073 invoked by uid 60001); 5 Dec 2006 22:02:29 -
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; 

h=X-YMail-OSG:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Conten
t-Type:Content-Transfer-Encoding:Message-ID; 

b=EB35j5LE7g7SFW+P1hAzS7Kob+z6Aaz02pv6hYoTR/yAf4dwTuwlsrilbNIMiXEfx/3/pZLzt

/7n9+9HlzHhoKGXYVZ/+OUe2hXqc3Kj3Yahg/77U+QYW9pA7FcuMT0HYgkL+TxT95GWujGwxxnk
a3ijdhFdcilAr9W7OJaaml0=;
X-YMail-OSG: SremAFkVM1kHYQsgCpAdmXqZfW.a9ow3eHJPGv59
Received: from [12.20.127.229] by web42403.mail.yahoo.com via HTTP; Tue, 05 
Dec 2006 14:02:29 PST
Date: Tue, 5 Dec 2006 14:02:29 -0800 (PST)
From: Derek B. Smith [EMAIL PROTECTED]
Subject: Re: Net::EasyTCP
To: beginners@perl.org
In-Reply-To: [EMAIL PROTECTED]
MIME-Version: 1.0
Content-Type: text/plain;
charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Message-ID: [EMAIL PROTECTED]
X-OriginalArrivalTime: 06 Dec 2006 21:53:43.0542 (UTC) 
FILETIME=[FF708160:01C71980]
X-TM-AS-Product-Ver: SMEX-7.0.0.1499-3.6.1039-14856.000
X-TM-AS-Result: No--28.715200-4.00-31
X-imss-version: 2.044
X-imss-result: Passed
X-imss-scanInfo: M:B L:E SM:3
X-imss-tmaseResult: TT:1 TS:-28.7152 TC:1F TRN:76 TV:3.6.1039(14858.000)
X-imss-scores: Clean:99.9 C:2 M:3 S:5 R:5
X-imss-settings: Baseline:3 C:3 M:3 S:3 R:3 (0.5000 0.5000)
X-Old-Spam-Check-By: la.mx.develooper.com
X-Old-Spam-Status: No, hits=0.8 

required=8.0tests=BAYES_00,DK_POLICY_SIGNSOME,DK_POLICY_TESTING,DK_SIGNED,D
K_VERIFIED,DNS_FROM_RFC_ABUSE,DNS_FROM_RFC_POST,DNS_FROM_RFC_WHOIS


--- zentara [EMAIL PROTECTED] wrote:

 On Sat, 2 Dec 2006 08:08:22 -0800 (PST),
 [EMAIL PROTECTED]
 (Derek B. Smith) wrote:
 
 I dont understand  there is no xs component and
 I
 dont understand  So you could actually include
 the
 EasyTCP code, as a package right into your script.
 
 Will u explain?
 derek
 
 Well, its the same thing as putting a module into
 your
 scripts running directory.
 
 For instance, instead of installing Net::EasyTcp
 system-wide,
 you could ( in your script's working directory) ,
 make a dir
 called Net, then in Net, copy EasyTcp.pm into it.
 Then in your
 script, put a 
 
 #/usr/bin/perl
 use lib '.'
 use Net::EasyTcp;
 
 and that will find your local copy.
 This is done all the time

Re: Net::EasyTCP

2006-12-05 Thread Derek B. Smith

--- zentara [EMAIL PROTECTED] wrote:

 On Sat, 2 Dec 2006 08:08:22 -0800 (PST),
 [EMAIL PROTECTED]
 (Derek B. Smith) wrote:
 
 I dont understand  there is no xs component and
 I
 dont understand  So you could actually include
 the
 EasyTCP code, as a package right into your script.
 
 Will u explain?
 derek
 
 Well, its the same thing as putting a module into
 your
 scripts running directory.
 
 For instance, instead of installing Net::EasyTcp
 system-wide,
 you could ( in your script's working directory) ,
 make a dir
 called Net, then in Net, copy EasyTcp.pm into it.
 Then in your
 script, put a 
 
 #/usr/bin/perl
 use lib '.'
 use Net::EasyTcp;
 
 and that will find your local copy.
 This is done all the time.
 
 To extend it even further, you could just copy
 EasyTcp.pm
 to a package in your script
 
 #/usr/bin/perl
 
 package EasyTcp;
 
 ... include EasyTCP.pm here, and edit it to remove
 the Net::
 
 1;
 
 package main;
 
 ... the real script
 
 
 zentara

yes I understand now. thx.
So moving on, I was able to gat all the files using an
scp script and for those w/out an ssh client I used
ftp. That was a freak-in pain!
Now I need to parse through all 238 files to pull
certain fields out delimited by :
My question is what does everyone think the most
practical way to go about this in terms of a data
structure?  No necessarily the best but most ideal. To
me ideal means most practical in an efficient way.

My 1st thought was a hash for each file wherein the
key would be the hostname and the values the fields.
I know there is a way to create dynamic hash's on the
fly but need some guidance on docs?

I then thought what about a hash containing a glob of
the files. 
my @diraray = glob(/home/dbsmith/draft_files.*);
The keys would be the filenames and the values would
be the fields after successive opens.  

In both situations, my goal is to attain the UID
fields that DO NOT match then print out the remaining
selected fields.

The file sizes range from 700 (18 lines) bytes to
50574k (614 lines).

thank you
derek



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




Re: Net::EasyTCP

2006-12-02 Thread Derek B. Smith

--- zentara [EMAIL PROTECTED] wrote:

 On Fri, 1 Dec 2006 20:31:11 -0800 (PST),
 [EMAIL PROTECTED]
 (Derek B. Smith) wrote:
 
 I was hoping for socket data transfers to mimic an
 sftp/ftp get without having to deploy code to the
 clients and or deploying this module on the
 clients.
 
 Think about it, how could that work?  You need some
 sort of code on the clients, whether it's your
 custom
 script, or existing server code. 
 
 Do the clients run a web server? You could place
 the files in a htaccess password protected
 directory,
 and get them thru https?
 
 There are many ways to go, http, ftp, ssh2, etc.
 
 You don't have to install the Net::EasyTCP module
 on the clients. There is no xs component, it's pure
 perl.
 So you could actually include the EasyTCP code, as
 a package right into your script.
 
 zentara
 

ok thanks 4 the advise, but I have thought about it.
All the clients do not have the same access routes.
For example, some have ssh turned on while others do
not. Those that do not, have ftp and the majority of
all the clients do not allow root login over ssh. So
now u see my dilemma... I have begun to use an scp
script, but I knew there was a way to use sockets to
xfer files so I thought I would learn something new
while I was getting all the files together.

I dont understand  there is no xs component and I
dont understand  So you could actually include the
EasyTCP code, as a package right into your script.

Will u explain?

derek

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




Re: Net::EasyTCP

2006-12-01 Thread Derek B. Smith
--- zentara [EMAIL PROTECTED] wrote:

 On Thu, 30 Nov 2006 13:34:16 -0800 (PST),
 [EMAIL PROTECTED]
 (Derek B. Smith) wrote:
 
 Hello... : )
 
 I need to gather a single filename on hundreds of
 servers ranging in *UX flavors from AIX, HP,
 Solaris,
 RH Linux and Tru64 then store them on on HPUX
 server.
 
 I was initially thinking an scp command like so
 foreach my $server in (@servers)
  scp /etc/passwd /tmp/passwd.$SERVER
 
 but not all clients have ssh running and other
 nuances
 such as no root ssh sign-in, no ftp, and
 /etc/passwd
 is protected from downloads and reads by anyone but
 root.
 
 I then looked at Net::EasyTCP for a socket
 download.
 As I read the CPAN info and after reading 
 
 
 For this to happen do I need to create server and
 client or just client? What do you recommend?
 
 server A would be server which houses gathered
 files
 server B would be client which is where unique
 passwd files live. 
 
 thank you
 derek
 
 It just so happens I played with this awhile back.
 Net::EasyTCP is a great time saver, because it
 handles port passwords, encryption, and
 serialization
 of hashes. It's neat to be able to send a hash thru
 a socket.
 
 You have 2 choices. 
 1. You can have the server RECEIVE files uploaded
 by the clients. This only requires 1 server to keep
 a port open, and the clients connect at random and
 upload their
 file, like thru a cron job.
  This is preferable because you only need 1
 constantly
 running socket open to the internet.
 
 #OR
 
 2. You can have each client running an open socket,
 and your collector connects to them and collects
 the
 file.
 
 I have working examples of both below. 
 
 Just remember, that Net::EasyTCP uses IO::Select,
 and if the files are big, the socket will block
 until
 the file is uploaded. This wouldn't be a problem
 if you use option 1.
 P.S. Use a port password, which Net::EasyTCP makes
 easy.
 
 See:
 http://perlmonks.org?node_id=198680
 
 Here is a version with a Tk front end:
 http://perlmonks.org?node_id=387351
 
 
 
 And finally, here is another client server pair to
 use
 as descibed in option 2 above. (Probably not the
 best way).


I did remember u posting this and saved that email
which is why I posted my question. : )
I will probably go with option 1.

thank you
derek

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




Re: Net::EasyTCP

2006-12-01 Thread Derek B. Smith
--- zentara [EMAIL PROTECTED] wrote:

 On Thu, 30 Nov 2006 13:34:16 -0800 (PST),
 [EMAIL PROTECTED]
 (Derek B. Smith) wrote:
 
 Hello... : )
 
 I need to gather a single filename on hundreds of
 servers ranging in *UX flavors from AIX, HP,
 Solaris,
 RH Linux and Tru64 then store them on on HPUX
 server.
 
 I was initially thinking an scp command like so
 foreach my $server in (@servers)
  scp /etc/passwd /tmp/passwd.$SERVER
 
 but not all clients have ssh running and other
 nuances
 such as no root ssh sign-in, no ftp, and
 /etc/passwd
 is protected from downloads and reads by anyone but
 root.
 
 I then looked at Net::EasyTCP for a socket
 download.
 As I read the CPAN info and after reading 
 
 
 For this to happen do I need to create server and
 client or just client? What do you recommend?
 
 server A would be server which houses gathered
 files
 server B would be client which is where unique
 passwd files live. 
 
 thank you
 derek
 
 It just so happens I played with this awhile back.
 Net::EasyTCP is a great time saver, because it
 handles port passwords, encryption, and
 serialization
 of hashes. It's neat to be able to send a hash thru
 a socket.
 
 You have 2 choices. 
 1. You can have the server RECEIVE files uploaded
 by the clients. This only requires 1 server to keep
 a port open, and the clients connect at random and
 upload their
 file, like thru a cron job.
  This is preferable because you only need 1
 constantly
 running socket open to the internet.
 
 #OR
 
 2. You can have each client running an open socket,
 and your collector connects to them and collects
 the
 file.
 
 I have working examples of both below. 
 
 Just remember, that Net::EasyTCP uses IO::Select,
 and if the files are big, the socket will block
 until
 the file is uploaded. This wouldn't be a problem
 if you use option 1.
 P.S. Use a port password, which Net::EasyTCP makes
 easy.
 


Isn't there rules for sending hashes or any data
structure over sockets? Does anyone have docs that
explain these?

thx
derek

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




Re: Net::EasyTCP

2006-12-01 Thread Derek B. Smith

--- zentara [EMAIL PROTECTED] wrote:

 On Thu, 30 Nov 2006 13:34:16 -0800 (PST),
 [EMAIL PROTECTED]
 (Derek B. Smith) wrote:
 
 Hello... : )
 
 I need to gather a single filename on hundreds of
 servers ranging in *UX flavors from AIX, HP,
 Solaris,
 RH Linux and Tru64 then store them on on HPUX
 server.
 
 I was initially thinking an scp command like so
 foreach my $server in (@servers)
  scp /etc/passwd /tmp/passwd.$SERVER
 
 but not all clients have ssh running and other
 nuances
 such as no root ssh sign-in, no ftp, and
 /etc/passwd
 is protected from downloads and reads by anyone but
 root.
 
 I then looked at Net::EasyTCP for a socket
 download.
 As I read the CPAN info and after reading 
 
 
 For this to happen do I need to create server and
 client or just client? What do you recommend?
 
 server A would be server which houses gathered
 files
 server B would be client which is where unique
 passwd files live. 
 
 thank you
 derek
 
 It just so happens I played with this awhile back.
 Net::EasyTCP is a great time saver, because it
 handles port passwords, encryption, and
 serialization
 of hashes. It's neat to be able to send a hash thru
 a socket.
 
 You have 2 choices. 
 1. You can have the server RECEIVE files uploaded
 by the clients. This only requires 1 server to keep
 a port open, and the clients connect at random and
 upload their
 file, like thru a cron job.
  This is preferable because you only need 1
 constantly
 running socket open to the internet.
 
 #OR
 
 2. You can have each client running an open socket,
 and your collector connects to them and collects
 the
 file.
 
 I have working examples of both below. 
 
 Just remember, that Net::EasyTCP uses IO::Select,
 and if the files are big, the socket will block
 until
 the file is uploaded. This wouldn't be a problem
 if you use option 1.
 P.S. Use a port password, which Net::EasyTCP makes
 easy.
 
 See:
 http://perlmonks.org?node_id=198680
 
 Here is a version with a Tk front end:
 http://perlmonks.org?node_id=387351
 
 
 


ok but is it possible to emulate an ftp get from the
master to retreive files from all clients w/out
deploying the client code to all clients using this module?

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




Re: Net::EasyTCP

2006-12-01 Thread Derek B. Smith

--- D. Bolliger [EMAIL PROTECTED] wrote:

 Derek B. Smith am Freitag, 1. Dezember 2006 20:31:
  --- zentara [EMAIL PROTECTED] wrote:
   On Thu, 30 Nov 2006 13:34:16 -0800 (PST),
   [EMAIL PROTECTED]
   I need to gather a single filename on hundreds
 of
   servers ranging in *UX flavors from AIX, HP,
 [snip]
   I was initially thinking an scp command like so
   foreach my $server in (@servers)
scp /etc/passwd /tmp/passwd.$SERVER
   
   but not all clients have ssh running and other
   nuances
   such as no root ssh sign-in, no ftp, and
   /etc/passwd
   is protected from downloads and reads by anyone
 but
   root.
 [snip]
   See:
   http://perlmonks.org?node_id=198680
  
   Here is a version with a Tk front end:
   http://perlmonks.org?node_id=387351
 
  ok but is it possible to emulate an ftp get from
 the
  master to retreive files from all clients w/out
  deploying the client code to all clients using
 this module?
 
 Hi Derek, 
 
 Sorry for not providing an answer to your question
 (I *think* your question is 
 answered by the manual. If not, wait for zentara :-)
 )
 
 I may miss something but it may make the person(s)
 who are responsible for  
 security nervous to hear of plans/thoughts
 
 - to transfer hundreds of passwd files unencrypted
 over the network
 - to place them in the /tmp directory with
 predictable file names
 - of seeing disallowed root login, locked down
 files, and missing
   ftp as a problem
 
 At least I would get nervous (although not having
 access to hundreds of 
 boxes...)
 
 Dani
 
 

I can understand you comments, but I am behind several
firewalls, I changed it from /tmp to my home dir with
permissions of 400. scp is being used as a work-around
while a manual login will have to be done for those
systems that do not have ssh turned on.
I was hoping for socket data transfers to mimic an
sftp/ftp get without having to deploy code to the
clients and or deploying this module on the clients.

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




Re: Question regarding use of multiple Perl versions

2006-11-30 Thread Derek B. Smith

--- Jay Savage [EMAIL PROTECTED] wrote:

 On 11/30/06, Hotz, Harry [EMAIL PROTECTED] wrote:
 
  I have a new AIX 5.3 server that comes
 with a default Perl 5.82.
  I have a DB2 programmer that has scripts from an
 old AIX 4.3 server that
  used Perl 5.005_03. He will have to rewrite his
 scripts to use the new
  Perl and asked me to install the old version side
 by side. I did so in a
  usr/lpp/oldperl directory and compiled it
 successfully. He took the user
  account under which the scripts are executing and
 added a path to the
  profile to point to the location of the old Perl
 but when he uses it and
  does a perl -version he still gets a return of the
 5.8 version. He feels
  this is a guarantee that his scripts will be
 hitting the wrong version
  and wants to know why he cannot version query the
 old Perl.
 
  My question is it even possible to
 successfully work with two
  versions of Perl..5.005 and 5.8 on the same
 server...and I don't mean
  just different modules. I saw that there is a use
 command to access
  different module versions but I don't know if that
 applies to using the
  whole Perl version. I do plan to insist he rewrite
 for the new version
  soon but if I could do anything for him quickly to
 make his scripts use
  the old version I will.
 
 
 It's absolutely possible. In fact, it's recommended
 when upgrading.
 
 The likely culprit here is the bang path. He can
 alias the shell
 variable, but if the first line of the script is
 still
 
 #!/usr/bin/perl
 
 then /usr/bin/perl is the Perl that will be used.
 What he needs to do
 is go into the scripts that he's worried about and
 point them to
 
#!/usr/lpp/oldperl/perl5.005_03
 
 ...or wherever the actual executable for the old
 Perl is hiding. It
 sounds like a lot of work, but he can automate it.
 
 HTH,
 

Also check that users PATH variable.
echo $PATH

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




Net::EasyTCP

2006-11-30 Thread Derek B. Smith
Hello... : )

I need to gather a single filename on hundreds of
servers ranging in *UX flavors from AIX, HP, Solaris,
RH Linux and Tru64 then store them on on HPUX server.

I was initially thinking an scp command like so
foreach my $server in (@servers)
 scp /etc/passwd /tmp/passwd.$SERVER

but not all clients have ssh running and other nuances
such as no root ssh sign-in, no ftp, and /etc/passwd
is protected from downloads and reads by anyone but
root.

I then looked at Net::EasyTCP for a socket download.
As I read the CPAN info and after reading 

Constructs and returns a new Net::EasyTCP object.
Such an object behaves in one of two modes (that needs
to be supplied to new() on creation time). You can
create either a server object (which accepts
connections from several clients) or a client object
(which initiates a connection to a server).

For this to happen do I need to create server and
client or just client? What do you recommend?

server A would be server which houses gathered files
server B would be client which is where unique
passwd files live. 

thank you
derek

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




Re: Forms Caching in FireFox?

2006-11-28 Thread WCJ d/b/a http://ccsh.us/

On 11/25/06, Richard Bagshaw [EMAIL PROTECTED] wrote:


  META HTTP-EQUIV=CACHE-CONTROL CONTENT=NO-CACHE
  META HTTP-EQUIV=PRAGMA CONTENT=NO-CACHE


HTML head isn't the same as setting an HTTP head;
Try Googling setting the Pragma: no-cache http header directly.
--
WC (Bill) Jones -- http://youve-reached-the.endoftheinternet.org/

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




win32 services

2006-10-27 Thread Derek B. Smith
Hello,  
I want to get a listing of Window services and each
associated status and its startup type.  I looked
at Win32::Daemon::Simple but wasn't sure if this is a
good module for doing so?  

W/out using a module, 
Is there a registry entry for each service I could
parse or a database that I could open and parse?

thx
derek


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

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




RE: win32 services

2006-10-27 Thread Derek B. Smith


--- Phil Miller [EMAIL PROTECTED] wrote:

 Try going to

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services.
 
 Bear in mind the name of the service does not
 directly correlate to the
 name of the Registry Key.  You have to look up under
 each key at the
 Value Name DisplayName.  I believe that is what is
 displayed in the
 Services MMC. The startup value is there, but if
 memory is correct, it
 is a numeric value.  The Microsoft web site have the
 documentation to
 tell you what the values mean, or you can do some
 experimentation to
 figure it out yourself.
 
 Also keep in mind that what shows up in the Services
 MMC are not ALL the
 Services the OS recognizes, but only the ones the
 writers of each
 Service chose to display in the MMC.  Go figure.  
 
 
 
 -Original Message-
 From: Derek B. Smith
 [mailto:[EMAIL PROTECTED] 
 Sent: Friday, October 27, 2006 9:23 AM
 To: Perl List
 Subject: win32 services
 
 Hello,  
 I want to get a listing of Window services and each
 associated status and its startup type.  I
 looked
 at Win32::Daemon::Simple but wasn't sure if this is
 a
 good module for doing so?  
 
 W/out using a module, 
 Is there a registry entry for each service I could
 parse or a database that I could open and parse?
 
 thx
 derek

The folliwing info was found at
http://www.microsoft.com/technet/archive/ntwrkstn/reskit/booting.mspx?mfr=true

Start Values
There is a Start value for each Services subkey in the
Registry key HKEY_LOCAL_MACHINE \SYSTEMcontrol
set\Services\DriverName. It specifies the starting
values for the device or service, as follows: 

• 0x0 (Boot) = Loaded by boot loader (NTLDR or
OSLOADER) before the Kernel is initialized. Disk
device drivers are examples of device drivers that use
this value. 
 
• 0x1 (System) = Loaded by the I/O subsystem during
Kernel initialization. The mouse device driver is an
example of a device driver that uses this value. 
 
• 0x2 (Auto load) = Loaded by Service Control Manager.
To be loaded or started automatically for all
startups, regardless of service type. The parallel
port device driver is an example of a device driver
with a value of auto load. The Alerter service is one
of the services that uses this value. 
 
• 0x3 (Load on demand) = Loaded by Service Control
Manager only when explicitly instructed to do so.
Available, regardless of type, but it is not be
started until the user starts it (for example, by
using the Devices option in Control Panel). 
 
• 0x4 (Disabled) = Do not load. Windows NT sets device
drivers to disabled when Service Control Manager
should not load them, such as when the corresponding
hardware is not installed. Having this value means
that the device drivers are not loaded by Service
Control Manager. File system drivers are the one
exception to the Start value. They are loaded even if
they have a start value of 4. If a device driver is
accidentally disabled, reset this value by using the
Services option in Control Panel. 

Note You can view the Start value of device drivers by
using the Devices option in Control Panel.

Since I did not see any specific CPAN modules out
there I may have to write one.
thank you
derek

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

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




Re: Evaluation of ++ different in C and perl?

2006-10-20 Thread Derek B. Smith
--- Paul Johnson [EMAIL PROTECTED] wrote:

 On Fri, Oct 20, 2006 at 08:11:36AM -0500,
 [EMAIL PROTECTED] wrote:
 
  Computer  software  consists of  only  two 
 components: ones  and
  zeros, in roughly equal proportions.   All that is
 required is to
  sort them into the correct order.
 
 Andrew Preview: You're playing all the wrong notes.
 Eric Morecambe: I am playing all the right notes...
 but not necessarily
 in the right order.
 
 But, without thinking too hard about it, I would
 have expected quite a
 few more zeros than ones in the average program.
 
 Hmmm.  Is it the weekend yet?
 
 -- 
 Paul Johnson - [EMAIL PROTECTED]


I am no Perl guru, but like to think of my self as
good at programming and enjoy it, but I am happy with
the clarity of perlop:

Note that just as in C, Perl doesn't define when the
variable is incre-
mented or decremented. You just know it will be done
sometime before or
after the value is returned. This also means that
modifying a variable
twice in the same statement will lead to undefined
behaviour.  Avoid
statements like:

$i = $i ++;
print ++ $i + $i ++;

So since its documented and not recommended and
considered bad coding I would say its not a bug.
However since the only thing higher that ++ or -- is 

left terms and list operators (leftward)
left -

and we tested () which had no result we wanted to see,
I guess we have to ask ourselves again what defines a
bug?


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

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




Re: Question about Installed Packages

2006-10-20 Thread Derek B. Smith

--- Chris Share [EMAIL PROTECTED] wrote:

 Thanks for the info. Isn't this what the Perl
 Package Manager is for?
 
 Rob Dixon wrote:
  Chris Share wrote:
  
  I'm trying to implement the following code:
 
 

##
 
  require LWP::UserAgent;
 
   my $ua = LWP::UserAgent-new;
   $ua-timeout(10);
   $ua-env_proxy;
 
   my $response =
 $ua-get('http://search.cpan.org/');
 
   if ($response-is_success) {
   print $response-content;  # or whatever
   }
   else {
   die $response-status_line;
   }
 
 

##
 
  The code works but what I don't get is how do I
 know if LWP::UserAgent 
  (or even LWP) is installed on my machine.
 
  If I use the Perl Package Manager and type: query
 LWP
  I get the following:
 
  Querying target 1 (ActivePerl 5.8.7.815)
1. LWP-UserAgent-Determined [1.03] a virtual
 browser that retries 
  errors
 
  This is a module (?) I installed myself.
 
  Is LWP::UserAgent installed--I guess it must be
 because the code works.
 
  Can someone explain this?
  
  
  First of all it should be
  
  use LWP;
  
  which does the 'require LWP::UserAgent' for you as
 well as checking that 
  you're
  running on an adequate version of Perl and setting
 the LWP version number.
  
  And you can find out whether LWP is installed by
 entering
  
  perl -MLWP -e1
  
  on the command line. It will shout if the module
 isn't there. Your 
  program will
  also die at the require if it doesn't find
 LWP::UserAgent, saying 
  something like
  'Can't locate LWP/UserAgent.pm in @INC'.
  
  HTH,
  
  Rob


yes but try pmtools.  It is a module that will give
you various info about what modules are installed and
where they live and what versions to name a few.


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

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




Re: More Info About $| = 1;

2006-10-19 Thread Derek B. Smith
-- Andreas Puerzer [EMAIL PROTECTED] wrote:

 Tom Phoenix schrieb:
  On 10/18/06, Chris Share [EMAIL PROTECTED]
 wrote:
  
  I've got a question about $| = 1;
  
  
  
  If I add $| = 1; at the top of the program this
 fixes the problem and
  the program runs as expected.
  
  
  Normally, output is buffered for efficiency;
 instead of writing each
  byte at once, output is saved in a buffer. The
 buffer is automatically
  flushed under various circumstances, such as
 end-of-program, or when
  the buffer gets full. Setting $| to 1 flushes the
 buffer after each
  print or printf statement, as you found, so it's
 much like having no
  buffer at all.
  
  Usually the buffer is flushed whenever the program
 stops to read
  input; your system seems to be an exception.
 Perhaps your perl binary
  is misconfigured? Or maybe you have a non-Unix
 system that does I/O
  differently than most. But what you describe isn't
 quite the
  documented behavior.
  
 
 It's not the documented behavior when running from
 the CLI, but the OP
 wrote:
 
 Chris Share:
  Hi,
 
  I'm a C programmer teaching myself Perl. I'm
 working on Windows XP using
  ActivePerl and Eclipse (EPIC).
 
 I've seen this with so many Editors (no, better:
 IDE's), it's definitely
 not a Perl issue, but, in this case, a Eclipse
 issue. I havn't dug too
 far into this, but each IDE (that I know  of) that
 offers to run perl
 inside its own Console suffers from this problem:
 there seems to be
 another layer of buffering going on (Eclipse calls
 this: 'Allocate
 Console') that makes it necessary to autoflush.
 
 So, to the OP, if  you want to take input from your
 program when run
 inside Eclipse, you will need to fiddle with $|, due
 to that
 extra-buffering-layer. If you run it outside
 Eclipse, there shouldn't be
 a need to do so.

Please review the online document for a clear
explanation of $|.

http://perl.plover.com/FAQs/Buffering.html


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

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




Re: More Info About $| = 1;

2006-10-19 Thread Derek B. Smith


--- Derek B. Smith [EMAIL PROTECTED]
wrote:

 -- Andreas Puerzer [EMAIL PROTECTED] wrote:
 
  Tom Phoenix schrieb:
   On 10/18/06, Chris Share [EMAIL PROTECTED]
  wrote:
   
   I've got a question about $| = 1;
   
   
   
   If I add $| = 1; at the top of the program this
  fixes the problem and
   the program runs as expected.
   
   
   Normally, output is buffered for efficiency;
  instead of writing each
   byte at once, output is saved in a buffer. The
  buffer is automatically
   flushed under various circumstances, such as
  end-of-program, or when
   the buffer gets full. Setting $| to 1 flushes
 the
  buffer after each
   print or printf statement, as you found, so it's
  much like having no
   buffer at all.
   
   Usually the buffer is flushed whenever the
 program
  stops to read
   input; your system seems to be an exception.
  Perhaps your perl binary
   is misconfigured? Or maybe you have a non-Unix
  system that does I/O
   differently than most. But what you describe
 isn't
  quite the
   documented behavior.
   
  
  It's not the documented behavior when running from
  the CLI, but the OP
  wrote:
  
  Chris Share:
   Hi,
  
   I'm a C programmer teaching myself Perl. I'm
  working on Windows XP using
   ActivePerl and Eclipse (EPIC).
  
  I've seen this with so many Editors (no, better:
  IDE's), it's definitely
  not a Perl issue, but, in this case, a Eclipse
  issue. I havn't dug too
  far into this, but each IDE (that I know  of) that
  offers to run perl
  inside its own Console suffers from this problem:
  there seems to be
  another layer of buffering going on (Eclipse calls
  this: 'Allocate
  Console') that makes it necessary to autoflush.
  
  So, to the OP, if  you want to take input from
 your
  program when run
  inside Eclipse, you will need to fiddle with $|,
 due
  to that
  extra-buffering-layer. If you run it outside
  Eclipse, there shouldn't be
  a need to do so.
 
 Please review the online document for a clear
 explanation of $|.
 
 http://perl.plover.com/FAQs/Buffering.html
 


I am running Eclipse and I also am seeing what u are
seeing.  

Eclipse SDK

Version: 3.2.1
Build id: M20060921-0945

The only fix I can see is placing this variable in
your template if you have configured one.
Window-Preferences-Perl EPIC-Templates-edit
Then to apply this template type in the keyword you
saved it as then it cntl spacebar and Eclipse will
place it where your cursor is.



The key is in the reading I suggested above...here is
a snippet of why you are seeing this:

Where's the buffering? Why didn't Perl save up the
output until it had a full buffer? Because that's
almost never what you want when you're writing to a
terminal, the standard I/O library that Perl uses
takes care of it for you. When a filehandle is
attached to the terminal, as STDOUT is here, it is in
line buffered mode by default. A filehandle in line
buffered mode has two special properties: It's flushed
automatically whenever you print a newline character
to it, and it's flushed automatically whenever you
read from the terminal. The second property is at work
here: STDOUT is flushed automatically when we read
from STDIN. 


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

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




Re: Evaluation of ++ different in C and perl?

2006-10-19 Thread Derek B. Smith
--- Dr.Ruud [EMAIL PROTECTED] wrote:

 Norbert Preining schreef:
 
  The Perl Book says: Auto increment and decrement
 work as in
  C. So if I take this C program:
  #include stdio.h
  #include stddef.h
  int main() {
   int a;
   int b;
   a=3;
   b=(++a)+(a++);
   printf(b=%d\n,b);
  }
  it prints b=8.
  
  When I do the same in perl:
  $a = 3;
  $b = (++$a) + ($a++);
  print b=$b\n;
  
  It prints b=9.
  
  I checked with a friend and Java behaves like C
 and prints 8.
 
 $ perl -wle '
   $a = 3;
   $b = 0 + (++$a) + ($a++);
   print b=$b\n;
 '
 b=8
 :)
 
 -- 
 Affijn, Ruud
 
 Gewoon is een tijger.
 


Lessons learned

always initialize your variables to zero. : )


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

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




Re: Evaluation of ++ different in C and perl?

2006-10-19 Thread Derek B. Smith
--- Rob Dixon [EMAIL PROTECTED] wrote:

 Derek B. Smith wrote:
  --- Dr.Ruud [EMAIL PROTECTED] wrote:
  
  Norbert Preining schreef:
 
  The Perl Book says: Auto increment and decrement
  work as in
  C. So if I take this C program:
  #include stdio.h
  #include stddef.h
  int main() {
   int a;
   int b;
   a=3;
   b=(++a)+(a++);
   printf(b=%d\n,b);
  }
  it prints b=8.
 
  When I do the same in perl:
  $a = 3;
  $b = (++$a) + ($a++);
  print b=$b\n;
 
  It prints b=9.
 
  I checked with a friend and Java behaves like C
  and prints 8.
 
  $ perl -wle '
$a = 3;
$b = 0 + (++$a) + ($a++);
print b=$b\n;
  '
  b=8
  :)
  
  
  Lessons learned
  
  always initialize your variables to zero. : )
 
 
 That's not initialising the variable, its, sort of,
 initialising the expression.
 
 $b = 0;
 $b += ++$a + $a++;
 
 (the parentheses are irrelevant) also gives 9. This
 looks like a bug to me, and
 v5.6 does it as well. Unless anyone can persuade me
 that this is correct
 behaviour?
 
 Rob
 

No I cannot, you are correct...init the expression. :
)
Have to remember this one.

I tried in on Active Perl 5.8.8 and Cygwin 5.8.7 and
it is behaving the same way.

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

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




Re: nice regular expression

2006-10-14 Thread I . B .

1. one of the purposes of scripting languages is creating prototype.
2. as i explained before my job is to create this perl regular expression.
Which will be used in xml file.
I dont care about clients apps, they can be written on any language. I use
perl.
3. also i greatly appreciate help of this community, I found solution using
help of my former colleague
and I posted it here for others interested individuals to see. It is all
about exercising skills. And having fun.
;)




On 14 Oct 2006 10:13:16 -0700, Randal L. Schwartz merlyn@stonehenge.com
wrote:


 I == I B [EMAIL PROTECTED] writes:

I unfortunately I have to use regex to solve this problem.

Why?  Is this homework?  Or is this a Java question in disguise?
Either of those are rude, having conned people into helping you
for false pretenses.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095
merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!

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





Re: nice regular expression

2006-10-13 Thread I . B .

thank you for reponse!
unfortunately I have to use regex to solve this problem.
I was trying to simplify:

$file=~/table.+Bug.+\/tr\s*tr.+\/tr\s*tr.+?\/tr\s*tr.+?\/tr\s*\/table/;

still does not work!!!







On 10/12/06, Dr.Ruud [EMAIL PROTECTED] wrote:


I . B . schreef:

 i have a task to verify that word Bug is in the table in the 3rd
 row from the buttom, i came up with regex , but it doesnt work.
 can anyone please take a look?

 #/usr/bin/perl -w

Get rid of the -w and insert

  use warnings;
  use strict;


 [...]

/table(.+Bug[^(tr)]+\/tr)\s*(tr.+\/tr\s+){2}[^(\/tr)]*\/tab
le/s);

You should not use a regex but a proper HTML parser.


Regarding your regex:

  [^(tr)]+

doesn't mean what you think it does. With the [^...], you are building a
character class that may not contain one of the characters ()rt.
See `perldoc perlre`.

--
Affijn, Ruud

Gewoon is een tijger.


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





Re: nice regular expression

2006-10-13 Thread I . B .

this is the problem:

use regular expressions to prove that word Bug
is in the 3 row from the end of table in the html tagged file:

shell cat file1.txt

table
 trtdrow 1/td/tr
 trtdrow 2/td/tr
 trtdrow 3/td/tr
 trtdBug some word/td/tr
 trtdrow 4/td/tr
 trtdrow 5/td/tr
/table

shell


shell cat file2.txt

table
 trtdrow 1/td/tr
 trtdrow 2/td/tr
 trtdrow 3/td/tr
 trtdBug some word/td/tr
 trtdrow 4/td/tr
 trtdrow 5/td/tr
 trtdrow 6/td/tr
 trtdrow 7/td/tr
/table

shell



this is my perl :


#!/usr/bin/perl

use warnings;
use strict;
my $file;
while(){
  $file.=$_;
}
print matches: $1\n if ($file =~
/table.+(Bug.+?)\/td\/tr\s*(tr.+?\/tr\s+){2}\/table/s);

shell

it does matches my string Bug some word in both file1.txt and
file2.txt, should only match file1.txt

frustrated!
what is wrong here?

thank you!


On 10/13/06, I. B. [EMAIL PROTECTED] wrote:


thank you for reponse!
unfortunately I have to use regex to solve this problem.
I was trying to simplify:

$file=~/table.+Bug.+\/tr\s*tr.+\/tr\s*tr.+?\/tr\s*tr.+?\/tr\s*\/table/;


still does not work!!!





On 10/12/06, Dr.Ruud [EMAIL PROTECTED] wrote:

 I . B . schreef:

  i have a task to verify that word Bug is in the table in the 3rd
  row from the buttom, i came up with regex , but it doesnt work.
  can anyone please take a look?
 
  #/usr/bin/perl -w

 Get rid of the -w and insert

   use warnings;
   use strict;


  [...]
 
 /table(.+Bug[^(tr)]+\/tr)\s*(tr.+\/tr\s+){2}[^(\/tr)]*\/tab

 le/s);

 You should not use a regex but a proper HTML parser.


 Regarding your regex:

   [^(tr)]+

 doesn't mean what you think it does. With the [^...], you are building a
 character class that may not contain one of the characters ()rt.
 See `perldoc perlre`.

 --
 Affijn, Ruud

 Gewoon is een tijger.


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






grouppin in the regular expressions

2006-10-13 Thread I . B .

Hi nice people,


how to specify using regular expressions: match everything but string (xxx)

i would do this :

$line =~ /[^(xxx)]+/;

but, as it was mentioned before () inside character class is not working.
what is solution here?

thank you!

~i


Re: nice regular expression

2006-10-13 Thread I . B .

got it! very nice, not complicated at all. I didn't know about lookahead
feature. very useful.

this file that should be matched:
TABLE
 TRTDrow 1/TD/TR
 TRTDrow 2/TD/TR
 TRTDrow 3/TD/TR
 TRTDBug some word/TD/TR
 TRTDrow 4/TD/TR
 TRTDrow 5/TD/TR
/TABLE

this is file that should not be matched:
TABLE
 TRTDrow 1/TD/TR
 TRTDrow 2/TD/TR
 TRTDrow 3/TD/TR
 TRTDBug some word/TD/TR
 TRTDrow 4/TD/TR
 TRTDrow 5/TD/TR
 TRTDrow 6/TD/TR
/TABLE

this is solution:

#!/usr/bin/perl
use warnings;
use strict;
my $file;
while(){
   $file .= $_;
}

if ($file =~
m{(Bug(?:(?!TR).)*)/TR\s+(TR(?:(?!TR).)*/TR\s*){2}\/TABLE}s){
   print matched: $1\n;
}
else{
print failed\n;
}


this is run:
$ regex.pl file1.txt
matched: Bug some word/TD

$ regex32.pl file2.txt
failed


thanx everyone!

On 10/13/06, Paul Johnson [EMAIL PROTECTED] wrote:


On Fri, Oct 13, 2006 at 12:36:33PM -0500, Charles K. Clarkson wrote:

 I.B. wrote:

 : unfortunately I have to use regex to solve this problem.

 Why do you have to use a regex?

Because that is what the question stipulates.

--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

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





Re: grouppin in the regular expressions

2006-10-13 Thread I . B .

sorry, I didn't fraze my question correctly.


example :
$line=abcxabcxxabcxxxabc;

how to match everything beofre xxx but not xxx itself?
the answer i got is to use lookaheads:

my $line = abcxxabcxxxabc;
if ($line =~ m{(.*?(?:(?!xxx).))xxx}){
print matched: $1\n;
}
else{
print failed\n;
}


very cool,
thanx everyone
~i


On 10/13/06, John W. Krahn [EMAIL PROTECTED] wrote:

 I.B. wrote:
  Hi nice people,

 Hello,

  how to specify using regular expressions: match everything but string
 (xxx)
 
  i would do this :
 
  $line =~ /[^(xxx)]+/;
 
  but, as it was mentioned before () inside character class is not
 working.
  what is solution here?

 Perhaps you want:

 $line !~ /xxx/;



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

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






nice regular expression

2006-10-12 Thread I . B .

Hi folks,

i have a task to verify that word Bug is in the table in the 3rd row from
the buttom, i came up with regex , but it doesnt work.
can anyone please take a look?



#/usr/bin/perl -w
my $line =
table\ntrtdA/td/tr\ntrtdBug/td/tr\ntrtdC/td/tr\ntrtdD/td/tr\n/table;
print 3 matches: $1\n if ($line =~
/table(.+Bug[^(tr)]+\/tr)\s*(tr.+\/tr\s+){2}[^(\/tr)]*\/table/s);

help really appretiated.
thanx
~i


Re: Non-deprecated way to capture array length

2006-10-09 Thread Derek B. Smith
--- Marc Sacks [EMAIL PROTECTED] wrote:

 I needed to find out the length of an array and did
 it by referencing 
 the array in scalar context. However, use warnings
 indicated that this 
 is a deprecated feature.  Is there a non-deprecated
 way to do this 
 (other than looping through the whole array until I
 run out of 
 elements)? Thanks.
 

Hi Mark, 

the best practice/standard way to get an array length
is:

print scalar @array_name,\n;
or
my $array_lnght = scalar @array_name;

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

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




canonpath

2006-10-06 Thread Derek B. Smith
I dont understand what the point of canonpath is here:
It seems to me canonpath only appply so links.

##-- Show me all installed Modules --##
use File::Find 'find';
use File::Spec::Functions;
  print Your installed modules on $^O are:\n;
  print - x 38,\n;
  find { wanted = sub { print canonpath $_\n if
/\.pm\z/ }, 
 no_chdir = 1}, 
  @INC;

#canonpath

I tried code with/out canonpath and the output is the
same.

I then lookup canonpath on CPAN and it tells me

*** No physical check on the filesystem, but a logical
cleanup of a path.

$cpath = File::Spec-canonpath( $path ) ;

Note that this does *not* collapse x/../y sections
into y. This is by design. If /foo on your system is a
symlink to /bar/baz, then /foo/../quux is actually
/bar/quux, not /quux as a naive ../-removal would give
you. If you want to do this kind of processing, you
probably want Cwd's realpath() function to actually
traverse the filesystem cleaning up paths like this.

thank you
derek


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

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




Re: Can't get Sudo.pm to run my command but it works from a prompt

2006-10-05 Thread Derek B. Smith

-- RICHARD FERNANDEZ [EMAIL PROTECTED] wrote:

 Hi folks,
 
 I have the following in a CGI script:
 

 
 When this code gets run (via webpage) I get the
 following in the
 error_log:
 
 snip
  output:  
  result: 256
 
 STDOUT: 
 STDERR: 
 We trust you have received the usual lecture from
 the local System
 Administrator. It usually boils down to these two
 things:
 
#1) Respect the privacy of others.
#2) Think before you type.
 
 Password:
 
 RC: 
 /snip
 
 In other words, it seems to be asking for a
 password. However when I run
 this from a regular prompt as the webserver user, it
 works fine.
 
 I have a check for the UID in the script, and it's
 the right one. I also
 have NOPASSWD set in sudoers.
 
 Any help is appreciated.
 Thanks!
 
 richf
 
 
 

Did you edit the sudoers file using visudo -f file
Show us the sudoers file using cat -etu file.
Has this user ever successfully logged in?

derek

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

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




RE: Can't get Sudo.pm to run my command but it works from a prompt

2006-10-05 Thread Derek B. Smith
--- RICHARD FERNANDEZ [EMAIL PROTECTED] wrote:

  Did you edit the sudoers file using visudo -f
 file
 
 Yes.
 
  Show us the sudoers file using cat -etu file.
 
 # cat -etu /usr/local/etc/sudoers 
 /tmp/sudoers.richf
 # less /tmp/sudoers.richf
 # sudoers file.
 #
 # This file MUST be edited with the 'visudo' command
 as root.
 snip
 
 # User privilege specification
 root ALL=ALL
 webuser  ALL = (ALL) NOPASSWD: ALL
 
 
  Has this user ever successfully logged in?
 
 Yes, the user is set up w/o a login shell, but in
 the course of testing
 I've given him login access. Doesn't make a
 difference.
 
  
  derek
  
 
 Thanks derek.
 

the cat -etu will show us any funky unneeded control
characters.
if the user has never signed in and the admin never
ran passwd user
passwd -f user and then that user never went into make
his/her password permenant then yes it would matter
b/c the passwd is not set.

Here is a working sample on me of my work production
systems:

ovuser  OVSYS = (root) NOPASSWD: /opt/OV/bin/,
/opt/OV/bin/OpC/, /opt/OV/bi
n/OpC/install/, /opt/OV/bin/OpC/utils/,
/opt/OV/contrib/OpC/, /data/data00/sbin/, /
data/data00/sbin/pre-exec/,
/data/data00/sbin/post-exec/,
/sbin/init.d/smtp_message
_interceptor, /db/u01/app/oracle/product/9.2.0/bin/,
/opt/OV/support/, /var/opt/OV/
bin/instrumentation/, /usr/local/ovo8x,
/usr/local/sbin/init.d/,/opt/CSCOpx/bin/, sudoedit
/etc/opt/OV/share/conf/C/filters



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

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




Re: Smart assignment

2006-10-03 Thread Derek B. Smith

 returns true or false (1 or '') and in list
 context it returns the
 contents of any capturing parentheses in the
 pattern.
 
 The expression:
 
 ( $ptypeline =~ /movable.+(sine|geo|radial|ortho)/i
 )[ 0 ]
 
 is a list slice so the regular expression is in list
 context but the slice is
 a single value so the expression is a scalar.
 
 The || operator will only work with scalar values,
 not with lists, so this
 works because the list has been converted to a
 scalar with the list slice.
 
 
 
 
 John


the list context represents everything between the / /
and the slice context represents [ 0 ] which is
assigned as a scalar to $ptypeline.

Correct?

thx
derek

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

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




Re: Listerine

2006-10-02 Thread Derek B. Smith
-- Mathew Snyder [EMAIL PROTECTED] wrote:

 Sorry.  Just had to do it.  :)
 
 -- 
 Mathew Snyder
 
 -- 

It got a laugh from me!

thank you

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

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




RE: Scope

2006-10-02 Thread Derek B. Smith
-- Charles K. Clarkson [EMAIL PROTECTED] wrote:

 John Ackley wrote:
 
 
 : while( ($service) = $SERVICE-fetchrow_array ) {
 
 According to the DBI docs:
 
If there are no more rows or if an error occurs,
 then fetchrow_array returns an empty list.
 
 When a value is returned, $service is set to
 that value.
 When we get to the end of the list, () is returned
 and
 $service is set to the undefined value. Since it
 tests
 false, the while loop stops with $service set to an
 undefined
 value.
 
 You can see this in the following script.
 
 use strict;
 use warnings;
 use Data::Dumper 'Dumper';
 
 my $service;
 
 ($service) = ();
 
 print Dumper $service;
 

John, 

For a complete understanding of scope (not listerine)
: )
please read the following:
http://perl.plover.com/local.html#2_Localized_Filehandles

and
http://www.perlmonks.org/?node_id=564448

Wow...opened my eyes and I now fully understand global
and non global variables.

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

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




Re: interpoliation within regexp

2006-09-29 Thread Derek B. Smith
I reread the docs and I am still unclear with the
code:
$a[ 10 + rand( @a - 10 )
I do understand everything but $a[ 10 + rand( @a - 10
)

b/c you say subtract 10 from each element occurrance
= @a - 10 then add 10 to the result of rand (@a - 10)
To me this is offsets itself which is why I am
confused. Will you explain again?
I think you missed an explanation step between a and
b?

Reagardless it work so thank you.


--- D. Bolliger [EMAIL PROTECTED] wrote:

 Derek B. Smith am Donnerstag, 28. September 2006
 22:28:
   Why not just specify a non-digit for the first
   character:
  
   my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z');
  
   my $password = join '', $a[ 10 + rand( @a - 10 )
 ],
   map $a[ rand @a ], 1 .. 5;
  
  
  
   John
 
  Ok great, but I do not fully understand this. Will
 you
  explain in English?
 
 Join with '':
 a) a randomly selected entry from @a excluding the
 digits
at positions 0..9 [the part between the 1st and 
2nd comma]
 b) five randomly selected entries from @a
[the map part]
 
 Note: @a is used in scalar context both times,
 meaning the number of entries 
 in @a.
 
 perldoc -f map
 perldoc -f join
 perldoc -f rand
 
 
 My tip for cases where you get a working solution
 you don't understand fully:
 a) Try to find out what belongs together (imagine
 '()'s)
 b) Try to break the solution apart according to the
 findings in a)
 c) examine the parts: print them out, dump them with
 Data::Dumper, modify
them, read the man pages
 d) put them together again, eventually one by one
 part, using examination 
techniques as in c)
 
 
 Hope this helps!
 
 Dani
 


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

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




using local when appropriate

2006-09-29 Thread Derek B. Smith


sub getfile {
 my $filename = shift;
 open F,  $filename or die open failed: $!;
 my $contents = '';
 while (F) {
  $contents .= $_;
 }
 close F;
 return $contents;
}

This is inefficient, because the F operator makes
Perl go to all the trouble of breaking the file into
lines and returning them one at a time, and then all
we do is put them back together again. It's cheaper to
read the file all at once, without all the splitting
and reassembling. (Some people call this slurping the
file.) Perl has a special feature to support this: If
the $/ variable is undefined, the ... operator will
read the entire file all at once: 

## Below is better pratice ##

sub getfile {
 my $filename = shift;
 open F,  $filename or die open failed  $!
 my $contents;
 { local $/ = undef;  # Read entire file at once
   $contents = F;   # Return file as one line 
 } 
 close F;
 return $contents;
}


I read an excerpt from
http://perl.plover.com/local.html#2_Localized_Filehandles

and was wondering if this holds true regarding
localizing $/ and setting it to undef in Perl 5.8.x?
Outside of a situation when localizing $/, is it best
practice to set $/ to undef considering If the $/
variable is undefined, the ... operator will read
the entire file all at once?

thx...
derek


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

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




Re: interpoliation within regexp

2006-09-29 Thread Derek B. Smith

-- Mumia W. [EMAIL PROTECTED]
wrote:

 On 09/29/2006 12:15 PM, Derek B. Smith wrote:
  --- D. Bolliger [EMAIL PROTECTED] wrote:
  
  Derek B. Smith am Donnerstag, 28. September 2006
  22:28:
  Why not just specify a non-digit for the first
  character:
 
  my @a = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z');
 
  my $password = join '', $a[ 10 + rand( @a - 10
 )
  ],
  map $a[ rand @a ], 1 .. 5;
 
 
 
  John
  Ok great, but I do not fully understand this.
 Will
  you
  explain in English?
  Join with '':
  a) a randomly selected entry from @a excluding
 the
  digits
 at positions 0..9 [the part between the 1st
 and 
 2nd comma]
  b) five randomly selected entries from @a
 [the map part]
 
  Note: @a is used in scalar context both times,
  meaning the number of entries 
  in @a.
 
  perldoc -f map
  perldoc -f join
  perldoc -f rand
 
 
  My tip for cases where you get a working solution
  you don't understand fully:
  a) Try to find out what belongs together
 (imagine
  '()'s)
  b) Try to break the solution apart according to
 the
  findings in a)
  c) examine the parts: print them out, dump them
 with
  Data::Dumper, modify
 them, read the man pages
  d) put them together again, eventually one by one
  part, using examination 
 techniques as in c)
 
 
  Hope this helps!
 
  Dani
 
  I reread the docs and I am still unclear with the
  code:
  $a[ 10 + rand( @a - 10 )
  I do understand everything but $a[ 10 + rand( @a -
 10
  )
  
  b/c you say subtract 10 from each element
 occurrance
  = @a - 10 then add 10 to the result of rand (@a -
 10)
  To me this is offsets itself which is why I am
  confused. Will you explain again?
  I think you missed an explanation step between a
 and
  b?
  
  Reagardless it work so thank you.
  
  
 
 Does this slice help demonstrate it?
 
 my @a = (0..9,'a'..'z','A'..'Z');
 my @b = @[EMAIL PROTECTED];
 print @a, \n;
 print @b, \n;
 
 # OUTPUT:

#0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
 #abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ
 #
 
 BTW, placing print statements in the right places is
 a great way to 
 learn how someone's program works. Anyway, I hope
 this is easier to digest:
 
 my @a = (0..9,'a'..'z','A'..'Z');
 my @b = @[EMAIL PROTECTED];
 
 my $password = $b[int rand (@b)];
 $password .= join '', map $a[int rand (@a)], (1..5);
 print $password, \n;
 
 __HTH__
 
 


yes this explains it... thank you.

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

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




Re: interpoliation within regexp

2006-09-28 Thread Derek B. Smith
--- Derek B. Smith [EMAIL PROTECTED]
wrote:

 I need to substitute a conversion using chr, but
 have
 failed on multiple attempts.  Basically if the first
 element contains a # then convert it. Will anyone
 advise?
 
 thank you
 derek
 
 #if first char is a-z then print it else warn
 #chop string into individual characters
 
 my @chars  = unpack
 (A1 x length($password),$password);
 
 if ($chars[0] =~ /^\D/) {
   print Your new string is:\t,@chars,\n;
 }
 else {
   print string starts with number, now
 converting\n,
 @chars, \n;
   substr($chars[0],0,1) =~
 s/\Q{$chars[0]}/{chr($chars[0]}\E/;
   print @chars;
 }
 

I will try to use the /e modifier as such:

s/(\$\w+)/$1/e;

An explanation is below:
/e
 Righthand side of a s/// is code to eval
 
/ee
 Righthand side of a s/// is a string to eval, then
run as code, and its return value eval'led again.
 



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

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




  1   2   3   4   >