Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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
Transposing rows to columns
4 direct replies — Read more / Contribute
by simak29
on Dec 18, 2014 at 01:38

    Hello, Newbie here. Is there a way that I can transpose DB rows into columns? I am thinking, that I can read the rows into a hashmap and then do some processing there, but am just not sure how to go about this.

    For example: If I have the below table:

    id name dept date_joined email date_sent 1 P1 Test 12/10/14 Y 12/11/14 10:53:45 1 P1 Test2 1/1/14 Y 1/05/14 05:25:34 2 P2 Test 3/1/14 N Null 2 P2 Test 8/1/14 Y 8/05/14 11:28:28 3 P2 Test3 10/1/14 N Null

    Desired Output is: id name Test Test2 Test3 Y_email N_E +mail 1 P1 12/10/14,8/1/14 1/1/14,3/1/14 10/1/14 12/11/14 10:53:45 +,1/05/14 05:25:35,8/05/14 11:28:28 Null 2 P2 1/1/14,3/1/14 null 10/1/14 Null, Null Basically, trying to transpose and flatten it to get one row per recor +d. Any ideas how I can do this?

    Can anyone suggest how I can go about this in the simplest way possible? The data I am dealing with is huge.

    Thanks in advance

How to install perl in custom directory on solaris.
3 direct replies — Read more / Contribute
by Ankur_kuls
on Dec 18, 2014 at 00:30

    Hi, I am facing many issues while installing perl modules with the default perl which comes with sun OS 10. Now I want to install perl in any custom directory. what I know and did is as below

    downloaded the latest perl in any directory (say /home/abc) unzipped and untar it. cd /home/abc/perl-5.20.1 ln -s /usr/sfw/bin/gcc /usr/bin/gcc ln -s /usr/ccs/bin/make /usr/bin/make ./Configure prefix=/customperl/cac make make test make install

    all three make command didn't show any failure but still I didn't get my perl installed in custom /customperl/cac directory. Could any one please tell me where I am wrong or provide me the complete steps to install this...thanks.

syswrite numbers, not strings
2 direct replies — Read more / Contribute
by akujbida
on Dec 17, 2014 at 23:19

    How to force syswrite to write numbers? A number is a numerical value; I do not mean the squiggly lines we draw to represent numbers.

    Perl keeps changing the values I try to write, in accordance with its 'does what you expect it to do' philosophy. Three days of official and unofficial documentation, I can't find a solution.

    Some examples of Perl changing types behind my back: with this line: syswrite($SERIALPORT, $packet_out)

    $packet_out = 4; On the serial wire: 0x34 (which is ASCII code for character 4) $packet_out = '4'; On the serial wire: 0x34 (which is ASCII code for character 4) $packet_out = 0x65; On the serial wire: 0x31 0x30 0x31 (which, bizarrely, is ASCII code fo +r '101' which is a string of the decimal ASCII code for 'e' which has + the ASCII code 0x65)
    When I say syswrite 4, I want a number 4 to go out the wire. This must be possible, and discussed already; anyone know how or where? I open the port like this:
    unless (open ($SERIALPORT, "+<", $comport)) {die "Cannot open $comport +: $!"} system("stty -cstopb hupcl ignbrk -iexten -echo -echoe -echok " . "-echoctl -echoke -crtscts -ignpar cs8 9600 time 5 -icrnl " . "-ixon -opost -isig -icanon -F $comport"); die unless binmode($SERIALPORT, ':raw:bytes'); #numerous variations tr +ied
adding another file type to a hash table
1 direct reply — Read more / Contribute
by Anonymous Monk
on Dec 17, 2014 at 15:30
    Hey, so im trying to write this script that will go through the current directory open up file types grab all "SRS_####" and sort them. now that part works but im also trying to grab the equivalent .log file that is associated with the ctl. basically every #_##_XXXXXXXX.CTL will have a .log that goes with it. i wanna add the SRS_#### that is referenced within the log and add it to the current hash table.
    sub main(){ my @files = glob("*.{ctl,inc}"); my %srss; open (OUT, ">SRS_List.txt") or die "Can't open file: SRS_List.txt" +; foreach my $file (@files){ open (IN, $file) or die "Can't open file: $file"; while (<IN>){ if (my @matches = ($_ =~ /SRS[_\s]?(\d+)/gi)){ foreach my $match (@matches){ if (!$srss{$match}){ $srss{$match} = 1; } } } } close (IN); print (OUT $file."\n"); if (keys %srss){ print OUT "SRS_(".join("|", sort {$a <=> $b}(keys %srss)). +")"; %srss = undef; } else{ print(OUT "NONE"); } print (OUT "\n\n"); } close(OUT); } main();
wxPerl button background
2 direct replies — Read more / Contribute
by xircon
on Dec 17, 2014 at 14:25
    In my search for enlightenment, I have stumbled....
    $button2->SetForegroundColour(Wx::Colour->new(177,77,77));
    Works.... Button text is red, but:
    $button2->SetBackgroundColour(Wx::Colour->new(177,77,77));
    (or whatever colour). Does nothing.
exists() for a hash child-key creates the parent key? Bug?
6 direct replies — Read more / Contribute
by AnonymousPerl1
on Dec 17, 2014 at 07:31

    I can't post exact code, due to it being confidential stuff, but for the first time in a few years of mucking about in Perl, I've found a behavior that caused me to raise an eyebrow. Wisdom welcome!

    use Data::Dumper; $hash{keyA}{keyB}{keyC}{keyD}=1; if (exists($hash{keyA}{keyB}{keyE}{keyF})) { print "Hi\n"; } print Dumper (\%hash); if (exists($hash{keyA}{keyB}{keyE}{keyF})) { print "Hi\n"; }

    The expected behavior should be "Hi" is never printed because keyE doesn't exist in the hash (and obviously keyF doesn't exist if keyE doesn't exist). However, what I'm seeing both by using ::Dumper and in foreach hash looping further along in the code is that $hash{keyA}{keyB}{keyE} is being "created" just by checking to see if {keyA}{keyB}{keyE}{keyF} exists, however even with another exists() call, "Hi" will not be printed.

    If I instead do this:

    if (exists($hash{keyA}{keyB}{keyE})) {
    then everything is fine and dandy and behaves as expected (keyE doesn't get created).

    Is exists() just a dangerous function to use for nested hashes? Or did I stumble on a bug?

Occasional Read Timeout with Mech
3 direct replies — Read more / Contribute
by pirkil
on Dec 17, 2014 at 06:17

    Dear monks, my script has to fetch some data from web, the mechanism looks like this:

    for my $try (1 .. 5) { debug("fetching HTML source: try $try of 5\n") if $debug; my $mech = WWW::Mechanize->new( autocheck => 0, ssl_opts => { verify_hostname => 0, SSL_version => 'TLSv1', }, timeout => 60, ); $mech->proxy('https', $args_hr->{proxy}); # Try::Tiny try { $mech->get( $url ); } catch { $err .= $_ if $_; }; my $text = $mech->content; $err .= "Can't fetch HTML source from $url!\n" if !$mech->s +uccess(); ... sleep 30; # before next try - if download was not succ. }
    I run this script on a server (with cron job). The URL is always the same. Sometimes I got en error, variable $text contains: read timeout at /usr/local/share/perl5/Net/HTTP/Methods.pm line 268. Other runs are OK, so I am not sure what the problem is and how to avoid it. Thanks for help!
Not a GLOB reference
2 direct replies — Read more / Contribute
by GeekyBrackets
on Dec 17, 2014 at 06:06
    I get this error for the line: while($line = <$fh>) What does it mean and how can I resolve it? The entire code is:
    use strict; use warnings; use v5.14; use Compress::Zlib; my $filename= "example.gz"; my $fh= gzopen($filename, "rb"); my $line=0; my $counter=1; my @array=(); [b]while($line = <$fh>)[/b] { @array= split (' ', $line); my $num = scalar(@array); print "$array[15] $array[1]\n" if ($array[15] eq "word"); $counter++; } close $fh;
Moose problem.
2 direct replies — Read more / Contribute
by Anonymous Monk
on Dec 17, 2014 at 03:33
    Why does give 'Use of uninitialized value in print' instead of printing "two"?
    use strict; use warnings; package Stuff { use Moose; has 'options' => ( traits => ['Array'], is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] }, handles => { all_options => 'elements', add_option => 'push', map_options => 'map', filter_options => 'grep', find_option => 'first', get_option => 'get', join_options => 'join', count_options => 'count', has_options => 'count', has_no_options => 'is_empty', sorted_options => 'sort', }, ); sub test { my ($self, $arg) = @_; $self->get_option($arg); } no Moose; 1; }; my $s = Stuff->new({elements => [ qw/one two three/ ] }); print $s->test(1);
Dear Monsk pls help me with that error
1 direct reply — Read more / Contribute
by sibyurik
on Dec 16, 2014 at 21:36

    It gives me an error no &wanted subroutine given at /usr/share/perl/5.18/File/Find.pm line 1073

    #!/usr/bin/perl # #Author: Yury Sibirski #Name: users_home_dir #Date: 16 December 2014 #Purpose: This program analyze the directory structure of a Linux disk + and identify any files larger than 500 kbytes # use File::Find; use strict; use warnings; my $path = shift || '.'; find($path); find( sub { return unless -r && -f; my $size = -s; print "$File::Find::name $size\n" if $size > 51200; }, $path );

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 drinking their drinks and smoking their pipes about the Monastery: (11)
    As of 2014-12-20 19:52 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (97 votes), past polls