Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Seekers of Perl Wisdom

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

If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this section is the place to ask. Post a new question!

However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.

User Questions
How to Generate text file by picking up string from other text file line by line
1 direct reply — Read more / Contribute
by snkhadse
on Dec 09, 2016 at 05:32

    How to Generate text file by picking up string from other text file line by line.

    my first file data.txt from where i want to pick string is

    ip mac 172.16.1.1 00-17-7c-0b-d4-ac 172.16.1.39 c4-17-fe-07-94-33 172.16.1.59 44-37-e6-ed-34-92 172.16.1.61 00-e0-4a-0a-2a-0a 172.16.1.63 00-30-18-a8-8b-ba 172.16.1.65 90-2b-34-5f-44-38 172.16.1.70 44-37-e6-ed-ab-a3 and i want to generate file aclallow.conf in format as below, http_access allow mac1 ip1 http_access allow mac2 ip2 http_access allow mac3 ip3 http_access allow mac4 ip4 http_access allow mac5 ip5 and aclip.conf as below acl ip1 src 172.16.1.55 acl ip2 src 172.16.1.56 acl ip3 src 172.16.1.57 acl ip4 src 172.16.1.58 acl ip5 src 172.16.1.59 and aclmac.conf as below acl mac1 arp 00:e0:4c:25:fc:9b acl mac2 arp 00:1F:D0:E0:73:F5 acl mac3 arp 00:25:64:AC:31:17 acl mac4 arp 44:37:e6:ed:d0:ae acl mac5 arp 44:37:e6:ed:34:92 Please help me for this .. Thanks in advance ..

Your wisdom on what to do with Apache 2.2 (eol) + mod_perl on Windows 64
No replies — Read more | Post response
by RayHunter
on Dec 09, 2016 at 05:31

    Greetings,

    I am seeking guidance on what is the righteous path to follow for a system currently running Windows Server 2012 64 bit, Apache 2.2, mod_perl 2.0.8 and Strawberry perl 5.16.3

    I realise that forward motion is required, but the momentum to remain stationary is great, so what is wisdom?

    I read that mod_perl is really for Apache 2.2. Apache 2.2 is good enough, but it's end of life. We really need mod_perl for speed. I really like Strawberry Perl. Windows is a given. So many paths that lead to disaster.

    What to do?

not able to insert data in database using perl DBI
2 direct replies — Read more / Contribute
by sachin raj aryan
on Dec 08, 2016 at 04:03
    my $dir = "tt"; my $date = "dd"; my $brnchid = "kk"; my $path = join "/",$dir,$date; my $dbfile = "xxx.xx.xx.xx"; my $dsn = "dbi:Oracle:host=$dbfile"; my $user = "ma"; my $password = "mama"; my $dbh = DBI->connect('dbi:Oracle:host=xx.xx.xx.xx;sid=orcl;port=1521 +;SERVER=POOLED',$user,$password, { PrintError => 1, RaiseError => 1, AutoCommit => 1, FetchHashKeyName => 'NAME_lc', TraceLevel => 4, }) or die "Canot create Databse Handle: $DBI::errstr() \n"; chdir ($path); open(my $fh,'< nwsa.txt') or die "Could not open file $!"; while (my $row1 = <$fh>) { if ($row1=~/^[AL]/) { my @sachin = split//,$row1; my $f_column = join ("",$sachin[0],$sachin[1],$sachin[2],$ +sachin[3],$sachin[4],$sachin[5],$sachin[6]); my $s_column = join ("",$sachin[7],$sachin[8],$sachin[9],$ +sachin[10],$sachin[11],$sachin[12],$sachin[13],$sachin[14],$sachin[15 +],$sachin[16],$sachin[17],$sachin[18],$sachin[19],$sachin[20],$sachin +[21],$sachin[22],$sachin[23],$sachin[24],$sachin[25],$sachin[26],$sac +hin[27],$sachin[28],$sachin[29],$sachin[30],$sachin[31],$sachin[32],$ +sachin[33],$sachin[34],$sachin[35],$sachin[36],$sachin[37],$sachin[38 +],$sachin[39],$sachin[40],$sachin[41],$sachin[42],$sachin[43],$sachin +[44],$sachin[45],$sachin[46],$sachin[47],$sachin[48],$sachin[49],$sac +hin[50],$sachin[51],$sachin[52],$sachin[53],$sachin[54],$sachin[55],$ +sachin[56],$sachin[57],$sachin[58],$sachin[59],$sachin[60],$sachin[61 +],$sachin[62],$sachin[63],$sachin[64],$sachin[65],$sachin[66],$sachin +[67],$sachin[68],$sachin[69],$sachin[70],$sachin[71],$sachin[72],$sac +hin[73],$sachin[74],$sachin[75],$sachin[76],$sachin[77]); my $trd_column = join("",$sachin[85],$sachin[86],$sachin[8 +7],$sachin[88],$sachin[89],$sachin[90],$sachin[91],$sachin[92],$sachi +n[93],$sachin[94],$sachin[95],$sachin[96],$sachin[97],$sachin[98],$sa +chin[99],$sachin[100],$sachin[101]); my @newdigit=split/[,]+/,$trd_column; my $string = join('', map { "$_" } @n +ewdigit); my $Receipt_Amount=($string*100)/100; print "$Receipt_Amount\n"; my $fourth_column = join("",$sachin[106],$sachin[107],$sac +hin[108],$sachin[109],$sachin[110],$sachin[111],$sachin[112],$sachin[ +113],$sachin[114],$sachin[115],$sachin[116],$sachin[117],$sachin[118] +,$sachin[119],$sachin[120],$sachin[121],$sachin[122],$sachin[123],$sa +chin[124],$sachin[125],$sachin[126]); my @newdigit1=split/[,]+/,$fourth_column; my $string = join('', map { "$_" } @n +ewdigit1); my $Receipt_Amount1=($string*100)/100 +; print "$Receipt_Amount1\n"; print "$f_column,","$s_column,","$Receipt_Amount,","$Recei +pt_Amount1,","$date,","$brnchid \n"; my $sql ="INSERT INTO nwsa (code_id,name_code,inr_col,out_ +col,brnch_id) VALUES (?,?,?,?,?)"; print "$sql\n"; my $sth = $dbh->prepare($sql); $sth = execute($f_column,$s_column,$Receipt_Amount,$Receip +t_Amount1,$brnchid); $sth->finish(); } } $dbh->disconnect(); close ($fh);

    not sure what is wrong in the program.. below is my output

    C:\Users\lala\Desktop\mama>nwsaparsing.pl DBI::db=HASH(0x1ae41b4) trace level set to 0x0/4 (DBI @ 0x0/0) in +DBI 1.636- ithread (pid 4464) -> STORE for DBD::Oracle::db (DBI::db=HASH(0x1ae41b4)~INNER 'Fetch +HashKeyNam e' 'NAME_lc') thr#126d844 STORE DBI::db=HASH(0x1ae41b4) 'FetchHashKeyName' => 'NAME_lc' <- STORE= ( 1 ) [1 items] at C:/Strawberry/perl/vendor/lib/DBI.pm +line 739 v ia at C:\Users\lala\Desktop\mama\nwsaparsing.pl line 16 -> STORE for DBD::Oracle::db (DBI::db=HASH(0x1ae41b4)~INNER 'ora_d +rcp' 1) th r#126d844 <- STORE= ( 1 ) [1 items] at C:/Strawberry/perl/vendor/lib/DBI.pm +line 739 v ia at C:\Users\lala\Desktop\mama\nwsaparsing.pl line 16 -> connected in DBD::_::db for DBD::Oracle::db (DBI::db=HASH(0x1ae +40c4)~0x1a e41b4 'dbi:Oracle:host=192.168.1.4;sid=orcl;port=1521;SERVER=POOLED' ' +mama' ** ** HASH(0x46b1f4)) thr#126d844 <- connected= ( undef ) [1 items] at C:/Strawberry/perl/vendor/lib +/DBI.pm li ne 746 -> STORE for DBD::Oracle::db (DBI::db=HASH(0x1ae41b4)~INNER 'dbi_c +onnect_clo sure' CODE(0x12829b4)) thr#126d844 STORE DBI::db=HASH(0x1ae41b4) 'dbi_connect_closure' => CODE(0x1282 +9b4) <- STORE= ( 1 ) [1 items] at C:/Strawberry/perl/vendor/lib/DBI.pm +line 755 v ia at C:\Users\lala\Desktop\mama\nwsaparsing.pl line 16 419041001.46 0 L01A ,CURRENT ACCOUNT + , 419041001.46,0,20161128,00336 INSERT INTO nwsa (code_id,name_code,inr_col,out_col,brnch_id) VALUES ( +?,?,?,?,?) -> prepare for DBD::Oracle::db (DBI::db=HASH(0x1ae40c4)~0x1ae41b4 +'INSERT IN TO nwsa (code_id,name_code,inr_col,out_col,brnch_id) VALUES (?,?,?,?,? +)') thr#12 6d844 dbd_preparse scanned 5 distinct placeholders dbd_st_prepare'd sql INSERT ( auto_lob1, check_sql1) dbd_describe skipped for INSERT <- prepare= ( DBI::st=HASH(0x1ae4e14) ) [1 items] at C:\Users\lala +\Desktop\sa chin\nwsaparsing.pl line 54 Undefined subroutine &main::execute called at C:\Users\lala\Desktop\ma +ma\nwsapa rsing.pl line 55, <$fh> line 11. -> DESTROY for DBD::Oracle::st (DBI::st=HASH(0x1ae4db4)~INNER) thr +#126d844 <- DESTROY= ( undef ) [1 items] at C:\Users\lala\Desktop\mama\nwsa +parsing.p l line 55 via at C:\Users\lala\Desktop\mama\nwsaparsing.pl line 55 -> DESTROY for DBD::Oracle::db (DBI::db=HASH(0x1ae41b4)~INNER) thr +#126d844 <- DESTROY= ( undef ) [1 items] at C:\Users\lala\Desktop\mama\nwsa +parsing.p l line 55 via at C:\Users\lala\Desktop\mama\nwsaparsing.pl line 55 C:\Users\lala\Desktop\mama>
what are some of the most powerful, complex, one-liners?
8 direct replies — Read more / Contribute
by f77coder
on Dec 07, 2016 at 22:57

    hello

    in general if people could post some hellishly complicated one-liners, I'd like to have a go at trying to figure them out

    no perl equivalent of fork bombs, thanks

    :(){ :|:& };: or
    bomb() { bomb | bomb & }; bomb
How to perform recursion in any OS?
4 direct replies — Read more / Contribute
by rollec
on Dec 07, 2016 at 19:09

    I'm making a program that allows a user to generate a HTML page of directories in a system. My issue is that I only made the code to work for linux. I need it to work for ALL operating systems. How can I do this?

    #!/usr/bin/perl use strict; use warnings; ### This program looks at the current directory and then makes a path +to all the sub directories. ### Step 1: Create a subroutine with Variables for the program. This i +ncludes the following: ### Files, Path and Directories. ### Step 2: make the program list the files and folders of current dir +ectory. Push folders into an array ### Step 3: Print Dirs ### Step 4: Recurse if (@ARGV != 1) { print "Usage: perl $0 [PATH/][TO/]DIR\n"; exit; } my $path = $ARGV[0] ; sub list { my $path=$_[0]; #print "DEBUG - listing [$path]\n"; chomp(my @files = `ls -a $path`); my @dirs; foreach(@files) { if (-d "$path/$_" && $_ ne "." && $_ ne ".."){ push (@dirs , "$path/$_"); } } print "-------------------------------------\n"; print "Generating HTML doc for path = [$path]\n"; open(FHOUT, ">", "$path/index.html") or die "Can't open '$path/index.html':$!\n"; print FHOUT "<!DOCTYPE html>"; print FHOUT "<html><head>" . "<title>listing:</title>" . "</head><body>"; print FHOUT "<ol>\n"; foreach( @files ) { if ($_ ne "index.html" && $_ ne "." && $_ ne "..") { print FHOUT "<li>"; print FHOUT "<a href='$_'>Parent</a>"; } if (-d $_) { print FHOUT "&nbsp;&nbsp;(DIR)"; } print FHOUT "</li>"; #print FHOUT "<br/>\n"; } } print FHOUT "</ol>\n"; print FHOUT "</body></html>"; close(FHOUT); #foreach (@dirs) { # print "$_\n"; #} ####+++++++++++++++ ## Now visit other dirs recursively: foreach (my @dirs) { &list($_); } exit;
binmode i/o for perl -pi in-place editing
2 direct replies — Read more / Contribute
by pryrt
on Dec 07, 2016 at 18:24

    how do you set binmode for the input and output of a perl -pi script.pl *.file in-place edit? I had hoped by doing binmode ${^LAST_FH}; binmode STDOUT;, that would cover it...

    I've gotten the input as close to binmode as I can, in that for the sample input above, the sum of the lengths of $_ totals 61, which matches that example input. But putting binmode STDOUT in either the BEGIN, the main, or both, does not seem to help the output file be the same length. I tried perl -C0 -pi... (from perlrun), hoping to make it all :raw equivalent, but with no change. I looked thru perlvar to try to find an output-equivalent of ${^LAST_FH}, but didn't see anything.

    In the end, I'll probably just stop trying the magic perl -pi and make a manual in-place loop, where I open the ARGV input and output handles myself, so I have full control. But after this much investigation, I'd really like to find out if it's possible to make the whole in-place pipeline binmode.

    ps: No, converting 'w' to 'v' is not my end goal :-). I just used that as a SCCE to show the basic problem binmode issue: I want to be able to do all my working (where my actual manipulations will preserve byte-length) without changing the EOL-like characters for this binary file.

Recomendations For Learning perl?
7 direct replies — Read more / Contribute
by adamZ88
on Dec 07, 2016 at 15:44

    All, I want to seriously expand my Perl knowledge. I am a network engineer and I have seen the powers of Perl and how it can make the job easier. I have limited programming experience. I took an intro to Java class, an HTML Class, a Ruby on rails class, and a programming for networking class where I learned Linux and pearl. Even though I like all of you monks, I would like to only come here for the real advanced stuff. How do you recommend that I go about mastering pearl programming? Do you have book recommendations or is it better to take a class?

Can't use string ("1") as an ARRAY ref while "strict refs
2 direct replies — Read more / Contribute
by seekinghelp12
on Dec 07, 2016 at 13:19

    Hi wise monks. This is a peculiar situation where I can run this code in windows activePerl(5.8)/strawberry perl(5.24.0) with no issues but when I try to run it in linux, I get an error: method nas:list_task has returned an error: Can't use string ("1") as an ARRAY ref while "strict refs" in use at (re_eval 127) line 1. Linux perl version is 5.10.1. Can you provide some insights as to why this might be the issue?

    I took a datadump in Windows of the returned result:

    #!/usr/bin/perl use Getopt::Long; use Pod::Usage; use Carp; use POSIX qw/strftime/; use Data::Dumper; use strict; #Export NA Library use Opsware::NAS::Client; #Declare Login Variables my($user,$pass,$host) = ('someuser', 'somepwd', 'somehost'); my $dttm = strftime('%Y:%m:%d:00:00:00',localtime); my $Diag_Date = $dttm; #Options GetOptions( "user=s" => \$user, "pass=s" => \$pass, "host=s" => \$host, 'help|h|?' => \my $help) or pod2usage(2); pod2usage(1) if $help; # open a CLI session my $nas = Opsware::NAS::Client->new(); my $res = $nas->login(-user => $user, -pass => $pass, -host => $host); #Handling login errors unless ($res->ok()) { printf STDERR ("*** error: %s\n", $res->error_message()); printf STDERR ("Did you supply valid Credentials?\n"); printf STDERR ("Please verify User/Password.\n"); exit(1); } my @listoftasks=("getSwitches","getFirewalls"); foreach my $specificTask (@listoftasks) { my $tasklist = $nas ->list_task( start => $Diag_Date, name => $specificTask, type => "Run Command Script" ); print Dumper($tasklist); }; $nas->logout(); # clean up undef $nas; #Inform Status print "\n\n\rStatus: Done!\n\n"; exit(0);
Term::ANSIMenu help
2 direct replies — Read more / Contribute
by PerlTwo
on Dec 07, 2016 at 11:42

    In the cpan example I can't work out how to add an attribute to a menu item eg item_fgcolor() Any help would be humbly appreciated.

Spreadsheet::Read - Changes and quest for feedback
2 direct replies — Read more / Contribute
by Tux
on Dec 07, 2016 at 10:37

    I've just updated Spreadsheet::Read with two major new features

    • OO interface
    • Add sheets to existing book

    The addition of OO is just to make the other changes easier. The functional API did not change at all:

    my $book = ReadData ("file.xls"); my $book = Spreadsheet::Read->new ("file.xls");

    That makes adding data from other sources possible (and intuitive)

    Spreadsheet::Read::add ($book, "file.csv"); $book->add ("file.csv");

    that makes it clear that when you go beyond a simple read of one Spreadsheet, this new OO interface is to be preferred.

    For types that do not store labels on sheets, like CSV and SquirrelCalc, one can now pass a label. (the default label for CSV is its filename).

    $book->add ("file.csv", label => "Testing");

    and my personal fav new OO is that you can now take a sheet as object and use that with methods

    my $sheet = $book->sheet ("Test"); # or numbered my $maxcol = $sheet->maxcol; my $maxrow = $sheet->maxrow; my $label = $sheet->label; $sheet->label ("New label"); my @row = $sheet->row (2); my @col = $sheet->col (6);

    When I presented this yesterday at the Amsterdam Perl Mongers meeting, it was received very well. The support for labels was added today after feedback during the short presentation.

    What was also asked is if it would now be possible to do more complicated tasks like merging, moving, copying rows/columns/blocks between sheets, but there was no useful example for that YET. We can all wander off in our fantasies and think of idiotic data moves, but that would result is an unworkable API.

    My quest here is if people think that new functionality is indeed useful, to come up with suggestions for the API, like

    # suggestions $sheet2->copy ("C5", $sheet1->block ("F6", "H20")); $sheet->deleterow (12); $sheet->deletecol ("D" .. "F"); $sheet->block ("A1", "D5", sub { ... });

    Open to useful suggestions. No promise all of them will be implemented and if, then no guarantee it will be available next week :P

    SHOOT!


    Enjoy, Have FUN! H.Merijn

Add your question
Title:
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (9)
    As of 2016-12-09 11:01 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      On a regular basis, I'm most likely to spy upon:













      Results (150 votes). Check out past polls.