Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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
Text Editor Qeustion
6 direct replies — Read more / Contribute
by Anonymous Monk
on Mar 03, 2015 at 15:26

    Hi Monks

    I started using gVim on Windows to write some sys admin type Perl scripts that could be from a few to about 200+ lines. I was earlier using Komodo Edit. While I really like gVim, the more I try to add stuff like neocomplete/syntastic, the slower/quirckier it becomes. Using PerlCritic throws ups wierd errors in gVim. I've spent weeks trying to fix it, but now it's at a point where I'm fighting more with the plugins than using it for writing scripts. Is there anyone here who uses something like KomodoEdit or similar? Do you think using Vim (or Emacs perhaps) actually makes you a better Perl Programmer? Can one still use an IDE and be a good Perl Programmer? Apologies if my question appears superfluous, but would be thankful if you folks could answer.

Recommendations for efficient data reduction/substitution application
7 direct replies — Read more / Contribute
by atcroft
on Mar 03, 2015 at 13:54

    Can anyone recommend the most efficient method of applying a large number of regular expression substitutions (> 100) to a relatively large number of input data lines (> 10_000_000)?

    In a recent project at $work, I wrote a script to generate a report of logged problem occurrences. In this process, I have to simplify the data by removing variations that are "noise" relative to the issues I am looking at (such as a process ID, an amount of free memory when a memory use threshold is crossed, or a part of a message with more detail than needed in this report). Once I've broken the record into a few basic parts, I currently have a list of 100+ regexen, replacement strings, and order of application to use (currently stored in a DB table), and a simple for loop to apply them to each record:

    foreach my $regex (@conversions) { if ( $entry{$k} =~ s/$regex->{from}/$regex->{to}/g ) { $regex->{count}++; # Count of applications used to determine if # a particular substitution is warranted. } }
    I have the nagging feeling, however, that there is a more efficient way of dealing with this. (Also, this processing takes up the largest percentage of the processing time in the script, which often takes hours to run.) Any thoughts/suggestions?

    Thank you for your time and attention, and any direction you may provide.

minimal match regulara expression
4 direct replies — Read more / Contribute
by fionbarr
on Mar 03, 2015 at 11:12
    I have a string that looks like:
    wppwd01a0099_NET_basp_virtual_adapter
    I want to capture the chars before the first '_' but what I end up with is: <code> wppwd01a0099_NET_basp_virtual <code> The regular expression I'm trying is: <code> if ( $this_server =~ m/^(\w+)_/ ) { $this_server = $1; } <\code> what am I doing wrong?
Exchange Heuristic and Swapping Code
1 direct reply — Read more / Contribute
by nat47
on Mar 03, 2015 at 10:54
    I posted a thread the other day and I didn't include any code. What I'm trying to do is: while the ideal state is still better than our current state, exchange 1 item for a different item in a leftovers array. So, the firs thing to do is check if the item to exchange fits, then check if it is a better $current_best. Right now I'm just trying to drop by order, pick first, loop through replacing the remaining items, then go back to the main loop change to second item. If state gets 'better' then the state is kept and looped through with that state. When the ideal state is met, it should stop.

    This is the code I've started to write, it doesn't work and isn't done in Perl fashion...

    @solution has the current set of items, @leftovers has the possible items that aren't inside @solution

    while($ideal_state > $current_best) { my $coun = 0; for(my $a = 0; $a < scalar @solution; $a++) { for(my $b = 0; $b < scalar @leftovers; $b++) { my $hold_previous = $solution[$a]; $solution[$a] = $leftovers[$b]; if($max_weight > totalweight(@solution)) { if(totalscore(@solution)>=$current_best) { $leftovers[$b] = $hold_previous; } } else { $solution[$a] = $hold_previous; } } #print "Main loop"; } }
Perl try { } catch(e) { }
2 direct replies — Read more / Contribute
by Superfox il Volpone
on Mar 03, 2015 at 09:16
    Hi there,
    I am looking for a way to implement the construct:
    try { die ("Hello world"); } catch(e) { print("Exception: " $e); }
    I know this snippet from Programming Perl 4th ed,pp 329, and it works using locals:
    sub try(&$) { my ($try, $catch) = @_; eval { # perl try &$try }; if($@){ # perl catch local $_ = $@; &$catch(); } } sub catch(&){ $_[0]; }
    And this works as try { ... } catch { print("Exception caught: $_"); };
    I'd like to refer the exception with something like catch(e){ ... }.

    I would prefer to avoid using any external module such as TryCatch for portability reasons.

    Thanks
    s.fox
Changing from http call to https using SOAP::Lite
1 direct reply — Read more / Contribute
by allwynpoikavila
on Mar 03, 2015 at 04:57
    Hello Monks, We are migrating our perl script to call https websites instead of http ones, but when we change the syntax of site inside the script from http to https to get the web data, we are getting error. what all changes needs to be done in the script so that it can get https websites data? our code uses SOAP::Lite for connecting to sever. can someone please help by posting the code snippet?, its urgent...
FTPSSL Bad file number
2 direct replies — Read more / Contribute
by Bettan
on Mar 03, 2015 at 03:49
    Hi, I'm not a perl programmer but I'm trying to modify an existing script from Net::FTP to NET::FTPSSL. Now there are problem to get the files. I got this error: syswrite() on closed filehandle GEN0 at Can't write command on socket: Bad file number This is part of the code:
    # GET FILE LIST if ( !$error_flag ) { if ( !$debug ) { @files = $ftp->list() or $error_flag = + 1; $ftp->quit if $error_flag; } else { opendir( DIR, "$debug_ftp_directory/$d +irectory_local" ) or $error_flag = 1; @files = readdir(DIR); closedir(DIR); } $report = $report . " ERROR: Can't get file l +ist $!\n" if $error_flag; $error_cnt++ if $error_flag; } # GET ALL FILES (*.enc) TO LOCAL DIRECTORY, DELETE THE +M ON SERVER foreach $file (@files) { if ( !$error_flag && $file =~ m/\.enc$/ ) { $report = $report . " Retrieving file + $file\n"; if ( !$debug ) { $ftp->get($file) or $error_fla +g = 1; $ftp->quit if $error_flag; $ftp->delete($file) or $error_ +flag = 1; $ftp->quit if $error_flag; } else { move( "$debug_ftp_directory/$d +irectory_local/$file", '.' ) or $error_flag = 1; } if ( !$error_flag ) { $downloaded_cnt++; } else { $report = $report . " ERROR: Can't re +trieve file $file $!\n"; $error_cnt++; } } } if ( ( !$error_flag ) && ( !$debug ) ) { $ftp->quit; }
    Would be greatful if someone can help me. This worked out with Net::FTP Thanks in advance Bettan
Calling a script from a script with GetOpt::Long arguments
3 direct replies — Read more / Contribute
by jjap
on Mar 03, 2015 at 01:26
    Dear Monks,

    I wrote a Perl script which receives 2 arguments specified with GetOpt::Long which I call the following way:

    perl heavylifter.pl --file thisfile --db thisdatabase

    To save myself some time, I made a script which makes a system call to that script over a list of files. However I am at a loss to find out how to specify the arguments in long form.

    To get by, I modified my heavylifter script to receive the file as $ARGV[0] and hardcoded the db in it to avoid the --db argument so the calling script looks like the following:
    use strict; use warnings; my @listFiles = ("thisfile", "thatfile", "thisotherfile"); foreach my $i (@listFiles) { print "file passed: $i\n"; system ("perl.exe", "full_path_to_heavylifter.pl", $i) ; }

    This is clearly a step backward and I would appreciate any guidance on how to properly call a script from a script with GetOpt::Long arguments.

    Best regards and thanks!
Debating With Friends
4 direct replies — Read more / Contribute
by exquisitemb
on Mar 02, 2015 at 23:22
    Hi All -- A friend is doing some weird embedded programming in C, and getting some strange results, so he asked what perl did (just for the sake of asking). I wrote up the quick comparison, and I got interesting results, now I'm intrigued. How/why does this work? (Yes, I know this is really stupid code)
    #!/usr/bin/perl $x; if(($x=1) eq ($x=2)) { print "equal\n"; } else { print "not equal\n"; }
    Result is that it gives is "equal". Why?
Divisors for a number
4 direct replies — Read more / Contribute
by rasy
on Mar 02, 2015 at 20:46

    Can some one help me to write a Perl script to get a number from the user and display the divisors of that number


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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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 the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (10)
    As of 2015-03-04 20:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When putting a smiley right before a closing parenthesis, do you:









      Results (129 votes), past polls