Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

The Monastery Gates

( #131=superdoc: print w/ replies, xml ) Need Help??

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
Net::SFTP::Foreign does not support both passphrase and password?
2 direct replies — Read more / Contribute
by khandielas
on Oct 13, 2015 at 12:32

    Hi, Monks, good day.

    I wonder anybody tried Net::SFTP::Foreign with priv key with passphrase and also password before?

    Here is a good thread about how to support both key and password authentication. salva gave a lot of explanations.But in this case, no passphrase was mentioned. Does Net::SFTP::Foreign support identity file and user password?

    In my case, if I pass passphrase in the hash, it will give me error: Invalid option 'password' or bad combination of options at ..../ line .... Here is the code sample:

    my $sftp = Net::SFTP::Foreign->new( $sftp_host, more => [ '-o', "IdentityFile=$ssh_key_path", '-o', 'PreferredAuthentications=keyboard-interactive,pas +sword,publickey', '-vvv' ], user => $sftp_user, password => $sftp_password, passphrase => $sftp_passphrase, timeout => 10, port => $port, stderr_fh => $my_err );

    I can manually log into remote server with passphrase and password typed in when being asked.

    Thank you very much.

Keep only X number of entries of a file using a delimeter
2 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 13, 2015 at 09:30
    Hi Monks!
    I have a big file that contains several thousands of entries, which are separated by the delimiter "#". What must I write to keep the first, say, 500 entries? I know how to split this file into 1 file per entry with awk for example, but I can't find a way to just keep a number of entries and discard the rest.
remove 16 Zeros
4 direct replies — Read more / Contribute
by eghdam
on Oct 13, 2015 at 04:47
    Hi Gurus,

    i am beginner and want to remove 16 zeros from thish String:

    pvid 00c1be9a467335ce0000000000000000


    if ($line =~ /pvid\+(.*$)"and remove 16 zeors) {

    $pvid = $1


    only getting this 00c1be9a467335ce from String. appriciate Your Help

    best regards ??? if ($line =~ /pvid\+(.*$)s{0000000000000000}{ $pvid = $1 } ???
How to get this not the usual round robin looping
3 direct replies — Read more / Contribute
by fidda
on Oct 13, 2015 at 00:40

    I have 2 sets of Arrays,

    @A = qw ( H1 H2 H3 H4); @B = qw (1 2 3 4 5 6 7 8 9 10);

    I need a way to return a hash with @A elemets as keys and @B elements as values, with one condition that hash should look like this.

    H1-> 1,8,9 H2-> 2,7,10 H3-> 3,6 H4-> 4,5


Perl assign scalar to array
3 direct replies — Read more / Contribute
by bagyi
on Oct 12, 2015 at 09:27
    Just a quick question
    my @a; # code that init @a @a[2..5] = 2;

    This assignment sets a elements at 2,3,4,5 to 2. The same works for hash slice. I would like to know if there is any documentation? And details of working. Is there any general concept behind like auto-vivification. I have looked in perl data tutorial.

    Oops sorry it is not working. I didn't use strict while testing this out.
Unexpected Excel TypeLib error
4 direct replies — Read more / Contribute
by merrymonk
on Oct 12, 2015 at 04:13
    Another mystery of Excel.
    I have had the following line of Perl for sometime in my Perl applications and modules used by a number of versions of Excel
    use Win32::OLE::Const 'Microsoft Excel';
    However a user is running Excel 2013 and gets the following message
    No type library matching "Microsoft Excel" found at module name line 77
    Win32::OLE(0.1703): GetOleTypeLibObject() Not a Win32::OLE::TypeLib object at C:/perl5/site/lib/Win32/OLE/ line 45
    Even with the message the application appears to run without any problems.
    Therefore I have removed this line and it appears to run in my Excel 2010 version without problems.
    Is is safe simply to remove this line (I have the same modules running in other versions of Excel)?
Value of $_ inside a regex
4 direct replies — Read more / Contribute
by Athanasius
on Oct 12, 2015 at 02:40

    I’ve just today discovered that, inside a regex, $_ takes on the value of the string being matched against:

    16:12 >perl -wE "my $string = 'abcde'; $_ = 42; say; $string =~ /(?{ s +ay })/;" 42 abcde 16:12 >perl -v This is perl 5, version 22, subversion 0 (v5.22.0) built for MSWin32-x +64-multi-thread

    This brings up two questions. First, is it documented anywhere? It’s not mentioned in the perlvar entry for $ARG.

    Second, what is the rationale for this behaviour?


    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Configure a switch with Win32::SerialPort
1 direct reply — Read more / Contribute
by Ghostth
on Oct 11, 2015 at 11:58

    I'm new at Perl and I need a script to configure an Arista Switch connected by a serial port. I installed the Win32::SerialPort module but I don't know exactly how to make the connection and how to configure the switch, e.g. put the username "admin" when the switch ask for it or establish "zero touch cancel" and wait for the reboot to continue with the configuration.

    Sorry for my bad inglish, it is not mother language and thank you for reading

Perl 6 on Windows 10
8 direct replies — Read more / Contribute
by CountZero
on Oct 10, 2015 at 14:34
    I just downloaded a recent version of Rakudo * (Rakudo 2015.6; MoarVM 2015.6) on my Windows 10 computer.

    When I try to run Perl 6 I get the error message "This version of MoarVM is not compatible with this version of Windows".

    Did anyone manage to get Perl6 working on Windows 10 yet?


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
CMS based Mojolicious
No replies — Read more | Post response
by morning_cat
on Oct 10, 2015 at 11:06
reference to an undefined key
2 direct replies — Read more / Contribute
by exilepanda
on Oct 10, 2015 at 08:20
    Hello monks,

    Sorry I believe I have given a pretty poor title but I really can't think of any better one, and I think this is the fact though. I'd like to know if there's any chance I can have such code candies ?

    my $obj = bless { Root => $rootDir, UserDir => $obj->{Root} . "Usr/$userId/", UserAppData = $obj->{UserDir} . "$appName/", }, shift; # of cause this won't work
    instead of :
    $obj = bless { Root => $rootDir, UserDir => undef, UserAppData => undef, }, shift; $obj->{UserDir} = $obj->{Root} . "Usr/$userId"; $obj->{UserAppData} = $obj->{UserDir} . "$appName";
    In fact I have much more paths that I need to defined while the object is created, but I hope to state the logic of the properties in clear at the first place.

    I guess I am out of luck but still trying to ask because when the interpreter read {Root}, that should be some place already stored the value ( but I juz don't know how to ref to it), no?


    I know why it's not working, what I try to emphasize is only inside the hash, so please forgive I didn't manage to give good code about the before and after.

    Though, I suddenly recalled something ( thank you very much for all you guys' feedback ). Yrs ago, I wrote a module for interpret an INI config file. Which accepts things like this:

    [ConfigDirs] A = /some/dir B = /_#A#_/DeeperDir C = /_#B#_/EvenDeeperDir
    And my module will go through it line by line. Every key recorded can be used by the next line. Regex will replace the _#*#_ with a proper recorded key's value. So it Data::Dump will produce something like
    $var = { 'ConfigDirs' => { 'A'=> '/some/dir', 'B'=> '/some/dir/DeeperDir', 'C'=> '/some/dir/DeeperDir/EvenDeeperDir' } }
    Now the questions can be added are: 1) is there any existing module deal's something like that? 2) is there any threat I elaborating things in this way?

    As I am going to reuse this module's code to let me accept params as I originally proposed.

optgroup with Perl CGI
1 direct reply — Read more / Contribute
by alokranjan
on Oct 10, 2015 at 07:30
    Hi All,

    I have a folder "items" under which I have files like: fruit and animal containing the names of fruits and animals respectively. Now I want to use optgroup select option.

    #!/usr/bin/perl print "Content-Type: text/html\n\n"; my @filename = split("\n", `ls items`); print <<HTML <html> <body> <select> HTML foreach(@filename){ print <<HTML <optgroup label="$_"> HTML open my $info, "items/$_" or die "Could not open $_: $!"; while( my $line = <$info>) { print <<HTML <option value="$line">$line</option> HTML } } print <<HTML </optgroup> </select> </body> </html> HTML
    Can anyone please suggest me what went wrong. Many thanks in advance !!

    Regards, Alok

New Cool Uses for Perl
tree command
3 direct replies — Read more / Contribute
by Skeeve
on Oct 13, 2015 at 04:09

    I'm, every now and then, missing a "tree" command at places where I have to work.

    And every now and then I "reinvent the wheel".

    To put an end to this, I decided to present my current version here.

    I hope it's useful to others and maybe I'll get some constructive feedback?

    Update: Added AppleFritter's suggestion of hiding hidden files

    #!/bin/env perl use strict; use warnings; use Getopt::Long qw(:config no_ignore_case); use Pod::Usage; my ( $showall, # show hidden files $showfiles, # show also files $showlinks, # show also a symlink's target ); help() unless GetOptions( a => \$showall, l => \$showlinks, f => \$showfiles, 'h|help' => \&help, 'm|man' => \&man, ); sub help { pod2usage(-verbose=>1); } sub man { pod2usage(-verbose=>2); } my $indent = ' '; my $indir = '--'; foreach my $path (@ARGV ? @ARGV : '.') { print $path,"\n"; traverse($path, ''); } sub traverse { my ($path, $depth) = @_; # Open the directory opendir my $dh, $path or die "Couldn't read $path: $!\n"; # Get all directory content - leaving out files unless asked for my(@content) = grep { not /^\.\.?$/ and ( $showfiles or not -f "$path/$_" ) and ( $showall or /^[^.]/ ) } readdir $dh; closedir $dh; # How many eitems are in the directory? my $count= scalar @content; # Prepare the standard indent my $i= $depth . '|' . $indent; # Print all the elements foreach my $sub (@content) { my $p= "$path/$sub"; # Prepare the last indent $i= $depth . ' ' . $indent unless --$count; print $depth, ($count ? '|' : '\\'), $indir , $sub; # Is it a link? if ( -l $p ) { # Shall they be shown as such if ($showlinks) { print " -> ", readlink $p; } print "\n"; next; } print "\n"; # Done unless it's a directory next unless -d $p; traverse($p, $i); } return; } =head1 NAME tree - A script to show a "graphical" representation of a directory st +ructure =head1 SYNOPSIS tree [options] [path...] =head1 DESCRIPTION tree will show a "graphical" representation of a directory structure, +including all files (when B<-f> specified) and link targets (when B<-l> specifie +d). =head1 OPTIONS =over 4 =item B<-f> Show also files. =item B<-l> Shhow also link targets. =item B<-h> =item B<--help> show a short help page. =item B<-m> =item B<--man> Show the man-page. =back =head1 AUTHOR Skeeve of (perlmonks DOT org DOT Skeeve at XoXy dot net) Including ideas of Apple Fritter, a fellow Perl monk =cut

New Obfuscated Code
Amusement Japh
1 direct reply — Read more / Contribute
by golux
on Oct 12, 2015 at 23:32
    Tested on both Linux and Windows, and requires the Tk module to be installed. There's a lot more I could add to the basic program, but the obfuscated version was already getting fairly large.

    Without giving too much away (and perhaps you've already guessed what it does), the arrow keys work the same as the keys 'h', 'j', 'k' and 'l'. Use ^C to quit, and try the <space> and 'n' keys too.

    Visually, there's a nice surprise when it runs (see if you can figure out the trick). I had a lot of fun getting the format "just right", and was pleased to see that "perl -MO=Deparse" didn't give anything away :-)


    s''$a=[];$ b=[];$c={} ;$d={};$e= [];$f={};$ g=[];use`T k;$W=MainW indow->new ;$W->iconi fy;$W->geo metry("1x1 -1-1");$W- >repeat(50 =>sub{$h`o r$W->deico nify;$i#0; if($o){#1i f$h++%5}el sif(!$j){# 1if$h++%20 }if($o){#3 Y=21;$Y>1; $Y--){my$J =$a#6Y];#3 X=0;$X<@$J ;$X++){my$ V=$J#6X]|| 0;(#7$o->{ $V})#2my$T =#5f->{$Y} ->{$X};my$ Z=$Y+1;$a# 6Y]#6X]=0; $a#6Z]#6X] =$V;$f->{$ Z}->{$X}=$ T;J($T,$X, $Z)}}$o=&M }my$N=0;#3 Y=2;$Y<22; $Y++){my$J =$a#6Y];my $K=1;#3X=0 ;$X<@$J;$X ++){(2==$J #6X])or$K= 0}if($K){+ +$N;$J->[0 ]=3}}if($N ){#3Y=2;$Y <22;$Y++){ my$J=$a#6Y ];(3==$J-> [0])#2#3X= 0;$X<@$J;$ X++){$a#6Y ]#6X]=0;(# 5f->{$Y}-> {$X})#4}my $L=5;#3Y=2 ;$Y<22;$Y+ +){my$J=$a #6Y];#3X=0 ;$X<@$J;$X ++){L($X,$ Y,2,$L++)i f(2==$a#6Y ]#6X])}}$o =&M;$o#0}@ $b`or`do{m y$M=$n||&I ;@$g`and`D ($g);$n=&I ;my$v=$d-> {$n}->[0]; for(@$v){m y($X,$Y)=@ $_;my$x0=4 24+14*$X;m y$y0=32+14 *$Y;my$G=[ $x0,$y0,14 ,14];my$T= B($c->{$n} ,$G);#8@$g ,[$x0,$y0, $T];}$m=$M ;my$Q=$d-> {$M}->[0]; $k=0;$b=[] ;for`my$w( @$Q){my($X ,$Y)=@$w;i f($a#6Y]#6 X+3]){for` my$R(keys% $f){my$x=$ f->{$R};ma p{$_->conf igure(-bg= >"gray")}v alues%$x}& F;$h=0;$b= [];#1$i=1} }my$I=0;fo r(@$Q){my( $X,$Y)=@$_ ;$X+=3;$I+ +or$l=$X;m y$T=B($c-> {$M},0);#8 @$b,[$X,$Y ,$T];J($T, $X,$Y);$a# 6Y]#6X]=1} #1&N};for( @$b){my($x 1,$Z)=($_- >[0],1+$_- >[1]);($Z< 22)or`goto `N;my$V=$a #6Z]#6x1]| |0;($V>1)a nd`goto`N} for(@$b){m y($X,$Y)=@ $_;$a#6Y]# 6X]=0;}for (@$b){++$_ ->[1];my($ X,$Y,$T)=@ $_;J($T,$X ,$Y);$a#6Y ]#6X]=1}#1 ;N:$j=0;wh ile(@$b){m y$w=shift@ $b;my($X,$ Y,$T)=@$w; $a#6Y]#6X] =2;$f->{$Y }->{$X}=$T }$b=[];&N; });$W->bin d("<Contro l-c>"=>sub {exit});$W ->bind("<K eyPress>"= >sub{my$E= shift;my$F =lc($E->XE vent->K);( $F`eq"n")# 0&E;@$b#0( $F=~/\Ah|l eft/)?G(-1 ):($F=~/\A l|right/)? G(1):($F=~ /\Aj|down/ )?H(-1):($ F=~/\Ak|up /)?H(1):(" space"eq$F )?$j=1:0}) ;&A;for`my $P([qw[I`1 59d`89ab`e a62`7654`c yan]],[qw[ J`159`8456 `a951`2654 `blue]],[q w[L`1598`4 56a`9512`6 540`orange ]],[qw[O`4 589`4589`4 589`4589`y ellow]],[q w[S`4158`4 59a`9562`6 510`green] ],[qw[T`14 59`4956`96 51`6154`pl um]],[qw[Z `459`8956` a651`2154` red]],){my $R=shift@$ P;my$O=$d- >{$R}=[];$ c->{$R}=po p@$P;map{m y$Q=[];my$ V=hex($_); for(1..4){ my$Y=$V&0x 03;$V>>=2; my$X=$V&0x 03;$V>>=2; unshift@$Q ,[$X,$Y]}# 8@$O,$Q}@$ P}map{B("b lack",$_)} ([128,648, 280,8],[12 0,620,8,36 ],[408,620 ,8,36]);Tk ::MainLoop ;^A{#9Y=0; $Y<22;$Y++ ){map{$a#6 Y]#6_]=0}( 0..9)}}^B{ my($B,$G)= @_;my$T=$W ->Toplevel ;$T->overr ideredirec t(1);$T->c onfigure(- highlightt =>1,-highl ightb=>"bl ack",-back ground=>$B );#1$G?K($ T,@$G):$T} ^C{my($X,$ Y)=@_;#1($ X<0or$X>9o r$Y<0or$Y> 21)?0:1}^D {my$t=pop; while(my$P =shift@$t) {$P->[2]#4 }^E{&A;D($ b);D($g);$ b=[];for(k eys%$f){my $S=#5f->{$ _};map{(#5 S->{$_})#4 keys%$S}&F ;$i=$j=$h= 0}^F{map{$ _->[0]#4@$ e;$e=[]}^G {my$D=pop; for`my$u(@ $b){my($X, $Y)=@$u;($ a#6Y]#6X+$ D]>1)#0;C( $X+$D,$Y)o r#1}my$I=0 ;for(@$b){ my($X,$Y,$ T)=@$_;--$ a#6Y]#6X]; ++$a#6Y]#6 X+=$D];J($ T,$X,$Y);$ I++or$l=$X ;$_->[0]=$ X}&N}^H{my $p=pop;($m `eq"O")#0; my$N1=($k+ $p)%4;my$A r=$d->{$m} ;my$As=$Ar #6k];my$At =$Ar#6N1]; my$O=[];my $N=[];#9I= 0;$I<@$b;$ I++){my$u= $b#6I];my( $X,$Y,$T)= @$u;my($x0 ,$y0)=@{$A s#6I]};my( $x1,$Z)=@{ $At#6I]};m y$D=$x1-$x 0;my$s=$Z- $y0;#8@$O, [$X,$Y];C( $X+=$D,$Y+ =$s)or#1;# 8@$N,[$X,$ Y,$T];}$b= $N;$k=$N1; #9I=0;$I<@ $O;$I++){m y($x0,$y0) =@{$O#6I]} ;my($x1,$Z ,$T)=@{$N# 6I]};--$a# 6y0]#6x0]; ++$a#6Z]#6 x1];J($T,$ x1,$Z);$I` or$l=$x1}& N}^I{@r=ke ys%$c;$r[r and@r]}^J{ my($T,$X,$ Y)=@_;K($T ,128+28*$X ,32+28*$Y) }^K{my($T, $X,$Y,$W,$ H)=@_;$W|| =28;$H||=2 8;$T->geom etry("${W} x$H+$X+$Y" );$T}^L{my ($X,$Y,$U, $V)=@_;#1i f$X<0or$X> 9or$Y<0or$ Y>21;if($U !=$V){($U= =$a#6Y]#6X ])or#1;$a# 6Y]#6X]=$V ;L($X-1,$Y ,$U,$V);L( $X+1,$Y,$U ,$V);L($X, $Y-1,$U,$V );L($X,$Y+ 1,$U,$V)}} ^M{my$E={} ;my$F={};# 9Y=2;$Y<22 ;$Y++){my$ J=$a#6Y];# 9X=0;$X<@$ J;$X++){my $V=$J#6X]| |0;($V>4)# 2++$F->{$V };next`if( #7$E->{$V} );my$Z=$Y+ 1;my$G=($Z >21)?4:$a# 6Z]#6X];($ G>0and$G!= $V)and++$E ->{$V}}}#9 Y=2;$Y<22; $Y++){my$J =$a#6Y];#9 X=0;$X<@$J ;$X++){my$ V=$J#6X]|| 0;(#7$E->{ $V})#2#5F- >{$V};$J#6 X]=2}}(key s%$F)?$F:0 }^N{&F;for `my$u(@$b) {my$X=128+ 28*$u->[0] ;my$G=[$X, 664,28,14] ;my$T=B("p urple",$G) ;push@$e,[ $T,$G]}}'; s+\s*++g;$o=0;for$l(' and return ',' return ',' or next;',########### ' for(my$','->destroy}','delete$','->[$','exists','push',# by golux # 'for(my$'){s&#$o&$l&g&&++$o}eval if s&\^&sub &g&&s&`&$"&g#2015-10-12#
    say  substr+lc crypt(qw $i3 SI$),4,5
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2015-10-13 23:43 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (318 votes), past polls