Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Perl Monk, Perl Meditation.
 
PerlMonks

Seekers of Perl Wisdom

 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | Snippets | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Code | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

( #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 is the place to ask.

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
Duplicate views to a single canvas using Perl TK
on May 03, 2008 at 00:07
1 reply by Helter
    I'm very new to Perl TK (read my first info this morning, so be easy correcting my possible slip ups in terminology...)

    I'm assisting a co-worker in editing an existing Perl TK application we use for debug. Currently it is a window, with a single frame, and a canvas in that frame.

    We would like to split the window so that we have the same content in an upper and lower view of the same data we had in the canvas already, but with independant scroll bars.

    We find that using this tool it would be helpful to have the header information that is printed at the top most of the time, but fairly often it would be nice to pull down the top canvas so we can compare things going on above and below (like splitting an editor screen in half and seeing 2 parts of the same file...at least in concept)

    We think we can solve this by duplicating the entirety of the canvas objects, but that seems heavy handed and sometimes the data that goes into generating these is fairly complex and time consuming.

    I wanted to believe that there was an easier way to do this than duplication, but my searches (for the last few hours) has come up empty.

    $top->title("Diagram Viewer");
    $top->configure(-background => 'white');
    
    #<a menu bar at the top>...skipping some details
    my $menu_bar = $top->Frame()->pack(-side => 'top', -fill => 'x');
    
    #skipping adding buttons to menu_bar....
    
    # the next frames
    
    my $top_canvas_frame = $top->Frame()->packAdjust(-side => 'top', -expa
    +nd => 'both', -fill => 'both');
    
    my $bottom_canvas_frame = $top->Frame()->pack(-side => 'bottom', -expa
    +nd => 'both', -fill => 'both');
    
    my $blankCanvas = { canvas => newCanvas($top_canvas_frame)};
    
    # here is where I can't figure out a way to insert another view $blank
    +Canvas into $bottom_canvas_frame so we can get dual views...
    <readmore>
    

[Offer your reply]
perl: Argument list too long
on May 02, 2008 at 23:43
6 replies by sjhalani
    Hi all, we have a shell script from which we invove the perl i.e a.sh ---- #!/bin/sh - -- we set a lot of environment variables here and then call perl script finally as :- $PERL_BIN/perl a.pl "$@" ----- The perl script has the following first line i.e --- #!/usr/local/bin/perl use lib (...) ... Usual processing ... ---- But when we invoke it we get the error a.sh bin/perl: Argument list too long The arguments we are passing are way within the limits i.e not more than 400 characters then why is the perl complaining on the argument list ? This is running on Linux box. Is there some limit on the number of environment variables we can set ?

[Offer your reply]
recognizing OS
on May 02, 2008 at 19:19
4 replies by PerlZealot
    I have a script which finds all the directories within a given directory and stores them in an array. In the original version of the script, I used something like this:
    my $dirname=cwd();
    my $sys_get_dirs = "ls -l $dirname | egrep \'^d\'";
    my @dirlist=`$sys_get_dirs`;
    
    I want to expand the script as a cross-platform script; both Linux and Windows. Is there a Perl function, command, structure - or something - I can employ in my script to somehow "detect" what OS it's running on? Is it something plainly obvious that I'm missing?

[Offer your reply]
undef==defined sometimes?
on May 02, 2008 at 19:09
2 replies by perl-diddler
    I'm not quite sure I understand this perl behavior.
    my @bar=undef; 
    print "def=",defined(@bar), " l=", $#bar, "\n";'
    
    output:
    def=1 l=0
    
    This is confusing me. I had a function that returned an array of answers if it found one or more answers, else it returned undef. On return, the result was assigned to an array and I tested the array for being defined or not.

    I thought that if my function returned undef and that was assigned to an array, the array should also test as not defined. Buuuut....noooooOOOOoooo.... :-(

    Why does my array, assigned "undef", then tell me it is defined? :-(... Very sad. I thought undef was the opposite of defined (sort of). I mean "undef" is a value (or an "unvalue"?), and defined is a test to see if a 'value' doesn't evaluate to 'undef', no? I'm sure there's a good reason for this, but at this point it sure doesn't seem "intuitive"...Arrg....

    (this is what I get for doing whatever it is that I've done to deserve this! :-))....


[Offer your reply]
substitution regex and unicode
on May 02, 2008 at 17:25
1 reply by frasco
    Maybe I'm tired but really I can't solve such a situation! I have the following script retrieving data from MySQL:
    #!/usr/bin/perl -w
    
    use strict;
    use warnings;
    use DBI;
    use CGI qw(:standard);
    use CGI::Carp qw(fatalsToBrowser);
    use utf8;
    use Encode qw(decode decode);
    binmode(STDOUT, ":encoding(utf8)");
    
    my ($datasource, $user, $passw, $dbh, $sth);
    my ($id_testo, $indice, $parole, $posizione);
    my (@row, $field);
    
    $datasource   = "DBI:mysql:database=Test;host=xxxxxxx;";
    $user  = "xxxxxxxx";
    $passw = "";
    $dbh = DBI->connect($datasource, $user, $passw) || die "Error opening 
    +db: $DBI::errstr\n";
    
    $dbh->do("SET NAMES 'utf8'");
    
    $sth = $dbh->prepare("SELECT indice, GROUP_CONCAT(parole SEPARATOR ' '
    +) FROM testo GROUP BY indice");
    $sth->execute();
    
    print header(-type => "text/html", -charset => "utf-8"),
        start_html(-encoding => 'utf-8', "My_database"), "\n",
        h2("ARET 1.1"), "\n";
    
    while (@row = $sth->fetchrow_array) {
        for $field(@row) {
        
        $field =~ s/([à]+)/<i>$1<\/i>/g;          # lower --> italic
        $field =~ s/(\p{Lu}+)/lc($1)/ge;          # upper --> lower
        $field =~ s/-=(.{1,4})/<sup>$1<\/sup>/g;  # OK
        
        }
        
    print p(),        
        decode("utf8", "$row[0]\t$row[1]\n");
    }
    
    $sth->finish();
    $dbh->disconnect() || die "fallita disconnessione\n";
    
    It gives me back the following output:
    .. various html tag and meta ..
    

    r.1,1 1 ʾà-da-um-=TUG2-II 1 AKTUM-=TÚG 1 IB2-IV-=TÚG SA₆ DAR

    r.1,2 g_*NI-ra-ar-=KI

    r.1,3 2 ʾa3-da-um-=TÚG-II 1 ʾa3-da-um-=TÚG-I

    Well, I really don't understand why the substitution regex doesn't work with unicode character such as accented wovel à (or Ú, or even the sign ʾ). I tried and change the à with its corresponding x{2be}, but nothing happens. My data originate from a MySQL table set with a utf8 charset. Is it possible that I didn't yet decoded my output when I send it to the for loop and to the sobstutions regex? Thank you

[Offer your reply]
die send to stdout & stderr
on May 02, 2008 at 17:03
3 replies by kehansen
    I have a program that uses DBI to perform sql tasks into an oracle database. I want to quit the program if an error is returned from the sql command. however, I want the error to go to STDERR and I want to print a custom message to STDOUT before dieing.
    my $dbh = DBI->connect('dbi:Oracle:miemsdb', 'ipse', 'ipse', {AutoComm
    +it => 0}) || die "RC-E\n";
    open (STDERR, ">ERR/ERRORS_${myPID}");
    
    ###########################
    
    my $DirChk = $dbh->prepare($sqlChkDir) || die "RC-E\n";
    $DirChk->execute($DirName) || die "RC-E\n";
    
    With this code I do get the oracle error and the "RC-E" into the ERRORS_$ file. But I want to send the RC-E to stdout.

[Offer your reply]
No av_splice function?
on May 02, 2008 at 16:06
2 replies by qumsieh
    Is there an equivalent of splice() that's accessible via XS?
    The closest I found was av_delete() which effectively undefs the element at the given index. Any way to shrink the AV?
    Thanks.

[Offer your reply]
correct way to use pp -a
on May 02, 2008 at 15:48
1 reply by alw
    Ladies and Gentlemen, I have been trying to add a data file to windows executable created with pp. The program cannot find the file unless it is in the same folder as .exe file as a separate file. The original .pl file expects the data file to be in the same directory as the script. It is in the archive, and I've tried placing it in /, /script, /lib. Nothing works. I can copy both the .exe file and the data file somewhere else and it does work but I want to not have to copy the data file, since it's already in the archive. I thought that the -a flag is for this purpose. I must be missing something here. test script named test.pl
    #!/usr/bin/perl
    # OS is windows XP perl 5.8.8 build 820 
    
    open FH,"hello.txt" or die "$!\n";
    while ( <FH> ) {
        print;
    }
    
    I have a text file in the same directory as the script named hello.txt. I then want to make an executable using pp: >pp -a hello.txt -o test.exe test.pl This creates an executable, but unless a copy of hello.txt is in the same folder, it will not find it. The -a flag did put the hello.txt file in the archive, but the script can't find it. Any ideas?

[Offer your reply]
Hash creation
on May 02, 2008 at 15:17
2 replies by applejacks
    Please point out the obvious to me :-) I've read in a file and built a hash with a single key and value pair. assume $input{red}= "yellow"; I'm trying to build a second hash using the values in the first hash. for example: $newhash = { new_value => $input{red} }; with the hope that $newhash{new_value} would have a value of "yellow". I am obviously doing something wrong.... Can someone please help me with this? Is there a different approach I should be taking? Thanks!

[Offer your reply]
Regex help - butchering text into paragraphs
on May 02, 2008 at 14:55
2 replies by throop
    Brethren

    I seek to split text, based on a bunch of keyword in the text, and shove it into a hash. I've been staring at 'Chapter 6: Pattern Matching' in the Perl Cookbook, but I just can't seem to get my mind around it. I'm pretty sure I need to be using the \G anchor, and non-greedy matching, but... I have an array of keywords like

    $Keyptr = 
    {PREFACE    => 1,
     ANALYSIS    => 1,
     DEFERRED    => 1,
     'NAME / NUMBER' => 1,
     CONCLUSION    => 1,
     EFFECTS    => 1,
     REMARKS    => 1}
    

    My input looks like

    @inputs =
      ("fronttrash PREFACE: mumble ^M ANALYSIS: yada ^M yada CONCLUSION: d
    +rone drone ^M REMARKS: ixnay",
       "ANALYSIS: Chuckle REMARKS: Yada2 DEFERRED: blahblah ^M blah ^M NAM
    +E / NUMBER: John 369")
    
    I want to coerce it into something like
    
    [{PREFACE => "mumble",
      ANALYSIS => "yada ^M yada", 
      CONCLUSION => "drone drone", 
      REMARKS => "ixnay"},
     {ANALYSIS    => "Chuckle",
      REMARKS    => "Yada2",
      "NAME / NUMBER" => "John 369",
      DEFERRED    => "blahblah^M blah"}]
    
    Is this the thing that can /should be done in a single golfed line? Alternatively, is there a module that I should be looking at?

    Thanks
    Throop


[Offer your reply]
 (1-10) of 300Next entries--> 

Add your question
Title:
Your question


  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read How do I compose an effective node title? and How do I post a question effectively? before you post!
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, 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
  • If you think you're going to use <pre> tags — don't! Use <code> tags instead! This applies to data as well as code.
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Login:
    Password
    remember me
    password reminder
    Create A New User

    Community Ads
    Chatterbox
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users
    Others avoiding work at the Monastery: (10)
    BrowserUk
    wfsp
    John M. Dlugosz
    atcroft
    grep
    castaway
    clinton
    pc88mxer
    exot
    im2
    As of 2008-05-03 14:34 GMT
    Sections
    The Monastery Gates
    Seekers of Perl Wisdom
    Meditations
    PerlMonks Discussion
    Categorized Q&A
    Tutorials
    Obfuscated Code
    Perl Poetry
    Cool Uses for Perl
    Snippets Section
    Code Catacombs
    Perl News
    Information
    PerlMonks FAQ
    What's New at PerlMonks
    Guide to the Monastery
    Voting/Experience System
    Tutorials
    Reviews
    Library
    Perl FAQs
    Other Info Sources
    Find Nodes
    Nodes You Wrote
    Super Search
    List Nodes By Users
    Newest Nodes
    Recently Active Threads
    Selected Best Nodes
    Best Nodes
    Worst Nodes
    Saints in our Book
    Leftovers
    The St. Larry Wall Shrine
    Offering Plate
    Awards
    Craft
    Quests
    Editor Requests
    Buy PerlMonks Gear
    PerlMonks Merchandise
    Perl Buzz
    Perl.com
    Perl 5 Wiki
    Perl Jobs
    Perl Mongers
    Planet Perl
    Use Perl
    Perl Directory
    Perl documentation
    CPAN
    Random Node
    Voting Booth

    Which came first?

    Chicken
    Egg

    Results (80 votes), past polls