Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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
Help with regex and 'like' in test::more
2 direct replies — Read more / Contribute
by neilwatson
on Jul 23, 2014 at 14:33


    I'm having a regex problem that I hope you can help me with. Consider this test:

    like( $content, qr(<td>$args->{class}</td> .* <td>$args->{timestamp}</td> )msix , '/report/classes dr_test_class ' );

    And the results:

    # Failed test '/report/classes dr_test_class ' # at ./ line 153. # '<tr> # <td>dr_test_class</td> # <td>2014-07-23 18:01:01-04</td> # </tr> # # ' # doesn't match '(?^msix:<td>dr_test_class</td> # .* # <td>2014-07-23 18:01:01-04</td> # )'

    Why does the match fail?

    Neil Watson

Printing particular column is not working
2 direct replies — Read more / Contribute
by kumarkeyan
on Jul 23, 2014 at 11:34
    Hi, I have to print the particular column from file. I have tried the below code
    my @header=qw/studentrecord primary_ins primary_ins_type/; my @wanted_fields = @header; open(DATA, "sample_1.csv") or die "Could not open file $!"; my @fields = split /,/, <DATA>; chomp @fields; while (<DATA>) { chomp; my %row; @row{@fields} = split /,/; my @wanted_data = map {$row{$_}} @wanted_fields; print join(",", @wanted_data), "\n"; }
    The above code is working fine if I give the field name in the header array(@header). But when I try to get the header value from file and assign that to @header, is not working properly.
    open (FH, "< sample_1_header.csv") or die "Can't open file for read: $ +!"; my @header=<FH>; my $i=0; foreach(@header) { my @array=$header[$i]; print @array; my @wanted_fields = @array; open(DATA, "sample_1.csv") or die "Could not open file $!"; my @fields = split /,/, <DATA>; chomp @fields; #print Dumper \@fields; while (<DATA>) { chomp; my %row; @row{@fields} = split /,/; my @wanted_data = map {$row{$_}} @wanted_fields; print join(",", @wanted_data), "\n"; } $i++; }
    And throws the below error. Use of uninitialized value $wanted_data[0] in join or string at line 39, <DATA> line 98. Let me know your thoughts on this.
Split columns according header delimiter
2 direct replies — Read more / Contribute
by sroux
on Jul 23, 2014 at 11:00
    Dear guruz all is in the title, I wish to split columns following header pattern (strange pattern indeed), the + sign is the delimiter here that turns then into fixed size delimiter for the next row... am I clear? not sure...

    Also as a second step, is there also a way of indexing the content using upper column title (sounds like a hash isn't it?)

    My example below is badly formatted but that's the whole idea, delimiter is where the + are Many thanks for your wisdom

    app db comment time blabla +--------+-----+----------+---------+------ one a rge 00:00:00 DFDF two b fghfjjf 00:00:00 fgfg three cc fjfjfj 00:00:00 fh four ddd fjgkk 00:00:00 tjku
Running perl scripts in parallel
1 direct reply — Read more / Contribute
by perl_help26
on Jul 23, 2014 at 10:48
    Hello ! I have two perl scripts : and that are supposed to run forever in parallel. Is it possible to call these scripts from a third perl script? i.e. ---------------------------- system('perl -w; system('perl -w;
Basic mod-perl question : why my variable is undefined ?
6 direct replies — Read more / Contribute
by pcouderc
on Jul 23, 2014 at 06:29
    O monks,
    I am lost with the following (simplified) script under apache and ModPerl::Registry :
    my $lig; ... $lig=4; print STDERR "ligA <<$lig>>\n"; sub xxxx { ... print STDERR "ligX <<$lig>>\n"; } print STDERR "ligB <<$lig>>\n"; xxxx();
    Sometimes I get (not always):
    ligA <<4>> ligB <<4>> ligX <<>>
    My question is , why $lig is undefined inside xxxx, and al least how can it be corrected ?
subroutine no error
2 direct replies — Read more / Contribute
by adriang
on Jul 23, 2014 at 06:19

    Hi all I realy don't understand why I dont get "Global symbol "%CS101" requires explicit" when I run:

    #!/usr/bin/perl # use warnings; use strict; use Carp; use 5.016; ave(); my %CS101 =("Joe Below" => 100, "Dan Gold" => 90, "Jon Kery" => 40, "Elton Jon" => 60, ); sub ave { foreach (keys %CS101) { print $CS101{$_}, "\n"; } } 1; __END__

    It only wotks if I put the hash at the top. Thanks in advance. Adrian

stuck during CPAN configuration
2 direct replies — Read more / Contribute
by all4perl
on Jul 23, 2014 at 06:04
    Dear folks, I am new to perl Monk. Please help me to solve the problem.. problem in running following command ./configure --prefix=/home/rose/temp/ bash: ./configure: No such file or directory
Net::SMTP halts script
1 direct reply — Read more / Contribute
by nperrins
on Jul 23, 2014 at 05:39

    Hi Guys,

    This is not something I had ever considered before, but I can find no solution on the web.

    We have a script that loops round, does some work and sends an email with Net::SMTP. However, if the SMTP->new cannot find the mailhost, it dumps out of the whole script with an undefined mailhost error.

    An example of this is a simple while ( $x < 4 ) loop round an SMTP email and a print $x gives 4 emails. Change the mailhost to an incorrect name and it crashes with an "undefined" error...but doesn't go past loop 1.

    Is there any way of catching this and skipping it?

    (I know the answer is to get the mailhost name correct, but with Microsoft now blocking port 25 to relay, users can change their relay servers if and when - so having a change in relay crashing your programs is not good.)

Search/format Across Multiple Lines
3 direct replies — Read more / Contribute
by HDTVJohn
on Jul 22, 2014 at 22:31

    First time I've posted here, would appreciate some hints. I would like to reformat some tricky text related to timecode. (Closed caption actually), and it has me spinning in circles. Here's a snippet of the text:

    \ TC: 16:12:48;28 14261426142D142D14701470AND W \ TC: 16:12:49;08 HI \ TC: 16:12:49;11 LE \ TC: 16:12:49;14 OVER \ TC: 16:12:49;19 T \ TC: 16:12:49;21 HE L \ TC: 16:12:49;24 AS \ TC: 16:12:49;27 T 10 \ TC: 16:12:50;07 14261426142D142D14701470YEARS \ TC: 16:12:50;17 W \ TC: 16:12:50;19 E' \ TC: 16:12:50;21 VE M \ TC: 16:12:50;25 AD \ TC: 16:12:50;27 E \ TC: 16:12:51;09 MAJ \ TC: 16:12:51;13 OR \ TC: 16:12:52;22 14261426142D142D14701470INVESTMENTS
    The 1xxx is the start of the text line that ends just before the timecode preceding the next 1xx, but I need to include the previous \TC: value, but delete all of the in-between TC values and the 1426 characters. End result ideally would be:
    \ TC: 16:12:48;28 AND WHILE OVER THE LAST 10 \ TC: 16:12:50;07 YEARS WE'VE MADE MAJOR....etc etc
    Matching patterns across lines, then going back to a previous line to collect and collate all of the numbers and text has me spinning. Any suggestions would be appreciated. Thx

Insecure Environment ?
2 direct replies — Read more / Contribute
by PapaJohn454
on Jul 22, 2014 at 18:00

    Greetings Perl Guardians

    Encountering a problem I've never seen before while running -T

    Insecure $ENV{ENV} while running with -T switch at /u/beta/coampsos/COSL/COAMPSOS/lib/ line 1496.

    NOTE it says $ENV{ENV} and not $ENV{PATH} line 1496 is: open(CMD,"$cmd 2>&1 |") || return ($!);

    From the following routine:

    # Runs a command under -T captures output ###################################################################### +######## sub run_cmd_safely{ my ($cmd) = @_; my ($DEBUG) = 0; #$DEBUG = 1 if ($cmd =~ /nexsat/i); if ($DEBUG == 1){ use CGI; my $query = new CGI; print $query->header; } print "<p>Initially command = $cmd\n" if ($DEBUG == 1); # Need to untaint and run in a restricted environment { $cmd =~ /([\~\*\w\_\-\%\+\/\.\,\!\s\"\'\|\\\>\<\&]+)/; $cmd = $1; } print "<p>After untaint cmd = $cmd\n" if ($DEBUG == 1); my ($ORIG_PATH) = $ENV{'PATH'}; $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin"; my (@RESULTS); # Remove any trailing | $cmd =~ s/\|\s*$//; print "<p>Really Running $cmd\n<p>" if ($DEBUG == 1); open(CMD,"$cmd 2>&1 |") || return ($!); print "Successfully opened $cmd\n" if ($DEBUG == 1); while(<CMD>){ chomp($_); next if ($_ =~ /sh /); next if ($_ =~ /grep /); print "<br>Pushing $_\n" if ($DEBUG == 1); push (@RESULTS,$_) if ($_ =~ /\w+/); } close (CMD); $ENV{'PATH'} = $ORIG_PATH; return (\@RESULTS); } ############################################################

    This routine runs fine on "most" machines. It's just not running on a customer's.

    Thank you for your help!

Add your question
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?

    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 cooling their heels in the Monastery: (11)
    As of 2014-07-23 21:21 GMT
    Find Nodes?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:

      Results (152 votes), past polls