Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

The Monastery Gates

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

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
Wide character in subroutine entry using encode_qp
1 direct reply — Read more / Contribute
by rumburak
on Jun 23, 2017 at 13:21
    use strict; use warnings; use utf8; use MIME::QuotedPrint; binmode STDOUT, ":encoding(UTF-8)"; my $str = "a\x{201E}z"; #my $str = "az"; #my $str = "a\x{201C}z"; #my $str = "a\x{03C9}z"; #my $str = "az"; #works print $str, "\n"; my $str_q = encode_qp($str); print $str_q, "\n";

    gives me this error message / faulty output:

    az Wide character in subroutine entry at ./ line 18.

    Only the fifth version of $str is working.... Can anyone tell me what is going here? (It is perl 5.24.1.)

Architecture design for full stack development.
4 direct replies — Read more / Contribute
by SimonClinch
on Jun 23, 2017 at 10:42
    Hi Monks, I am developing a website from scratch which will hopefully have plenty of activity some time in the future after it goes live. Although I am still developing it on Windows, I will migrate it to Linux/Apache, with Perl and Postgres completing the rest of the picture before and after migration. I am inclined to avoid PHP for performance reasons.

    While loading the database with some initial reference data (about 1GB), using one-off code that got fixed as I went along, I somehow managed to "lose" some PK values, because sequences do not roll back if accessed with nextval.

    But it occurred to me that when the system goes live, it will need to manage deleted values. Although I was careful to use bigint for PK values where necessary, I don't want to have the situation where the PK values stay fragmented and increase fragmentation over time.

    It was at this point that I realised I needed DBIx::Class, otherwise I would have layers of raw SQL hiding in any homegrown DBMS/Perl framework and that had to be avoided at all costs.

    So I am at the point where I have installed DBIx class and feel obliged to determine the rest of the architecture (MVC perhaps) and at the same level of detail, before writing any methods to dynamically defrag my keys (probably through use of an idpool table/class where inserters will look before calling nextval if nothing is in the pool for the table).

    It becomes clear that the defrag code belongs in the "Controller" part of the framework. But having never built a Controller before, I am hoping for advice on what the classes should look like in there, e.g. should I have a dbController class that uses methods in DBIx. Should it inherit from the Schema and/or should I have some kind of parent-of-all utility class? I am keen to make a good choice now rather than have to make fundamental architecture mods later. Many thanks in advance,


    One world, one people

Memory needed for perl process
4 direct replies — Read more / Contribute
by bsshetty17
on Jun 23, 2017 at 02:26

    Hi Monks, 2 quick questions. 1) What is the minimum memory required to start a perl process? 2)I need to install following cpan modules in HP_UX: \t Text::CSV_XS; \t SOAP::Lite; \t XML::Twig; \t Config::IniFiles; \t Parallel::ForkManager; Informatica is also installed in the same server. Informatica administrator is not agreeing to install the modules saying, It causes the informatica performance degradation. Can any one help to defend this? Thanks,

mod_perl best practices to increment XML payload
1 direct reply — Read more / Contribute
by glasswalk3r
on Jun 22, 2017 at 17:23

    Hello monks,

    I've being studying mod_perl in the past to implement a project that uses Apache as a reverse proxy, receives a SOAP request, modifies the payload (XML), handles it to the real web application, and returns back the response to the requester.

    What is the best practice in this case? I checked out Apache::ReverseProxy, but it defines a full handler and I'm guessing that using a Input or Output filter handler would be a better option (based on my readings of mod_perl2 User Guide book) combined with the standard Apache modules proxy and proxy_http to avoid reinventing the wheel.

    PS: I know mod_perl2 is not the "sexiest" framework at the moment, but I want to take advantage of already having it available on particular web servers by default.


    Alceu Rodrigues de Freitas Junior
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
Pulling from a list and inserting into XML documents
4 direct replies — Read more / Contribute
by gng4life
on Jun 22, 2017 at 09:25
    Hello All, First post so go easy on me. I'm getting back into Perl after not touching it for years so I am like a noob. This is what I need to do. I have text file A that three fields, for example IP address, MAC, hostname, and there about 200 of them, comma separated (I can change this to a csv or whatever if easier). I have about 200 XML documents that I need to search for tags and enter those three fields above into that section, save it, open the next document and enter the same three fields, save, repeat for all docs. Here is an example:
    File A hosta,,00000C123456, hostb,,00000C123457, hostc,,00000C123458, hostd,,00000C123459, etc...(about 200 items, will have more later) File 1 . <HOST_NAME></HOST_NAME> <HOST_IP></HOST_IP> <HOST_MAC></HOST_MAC> . . File 2 . <HOST_NAME></HOST_NAME> <HOST_IP></HOST_IP> <HOST_MAC></HOST_MAC> . . File 3 . <HOST_NAME></HOST_NAME> <HOST_IP></HOST_IP> <HOST_MAC></HOST_MAC> . . After all the docs are done, they will look like this... File 1 . <HOST_NAME>hosta</HOST_NAME> <HOST_IP>,</HOST_IP> <HOST_MAC>00000C123456</HOST_MAC> . . File 2 . <HOST_NAME>hostb</HOST_NAME> <HOST_IP>,</HOST_IP> <HOST_MAC>00000C123457</HOST_MAC> . . etc.
    I have portable strawberry Perl right now on my work computer. If it would be easier to do it in ActivePerl or in Strawberry Perl installed version, let me know and I can spin it up on another workstation. So what is the best way to do this? Thanks for any help!
An overlapping regex capture
2 direct replies — Read more / Contribute
by Peter Keystrokes
on Jun 21, 2017 at 15:18

    Hi there,

    I have a script which extracts sequences from a file containing thousands of fasta sequences and creates separate files for each of them.

    Here is my script:

    #!/usr/bin/perl use strict; use warnings; my %id2seq = (); my $id = ''; open File,"human_hg19_circRNAs_putative_spliced_sequence.fa",or die $! +; while(<File>){ chomp; if($_ =~ /^>(.+)/){ $id = $1; }else{ $id2seq{$id} .= $_; } } foreach $id (keys %id2seq){ if (-f $id){ print $id." Already exists, about to override it","\n" } open my $out_fh, '>>', "$id.fa" or die $!; print $out_fh (">".$id."\n",$id2seq{$id}, "\n"); close $out_fh; } close File;

    Now, the human_hg19_circRNAs_putative_spliced_sequence.fa file which I am working on contains sequences as such:



    My script captures each sequence header as the key of a hash and captures the sequence itself as the hash. But the problem is that I want to name the files with only a part of the $id and not the whole of it i.e. hsa_circ_0000001.

    Is there a simple way to do this? Or do I have to create a new hash to extract filenames?


from txt file to array
6 direct replies — Read more / Contribute
by WisDomSeeKer34
on Jun 21, 2017 at 15:01

    I have raw data like this:

    New York

    and I want to turn it into an array:
    qw (Washington, New York ....);

    I can do it manually but it is a fuzz to do it every time.
    Is it perhaps possible with while (< DATA >)? How to input raw data into a perl script?

using a 'here' doc to build a web page
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 21, 2017 at 11:23
    I am constructing a web page by first defining variables which are extrapolated in the 'HERE' document. I am creating a HTML file by printing the 'HERE' document. It seems to be working OK. Is this a valid approach?
How to tie a lexical filehandle.
1 direct reply — Read more / Contribute
by clueless newbie
on Jun 20, 2017 at 15:28


    I can do a tie on a file as long as I use bareword filehandles. ie

    package MyTie; use Carp; # So we can croak our error use Data::Dumper; use strict; use warnings; sub TIEHANDLE { #Carp::cluck "\nTIEHANDLE: ",Data::Dumper->Dump([\@_], +[qw(*_)]),' '; no warnings; my $class=shift; my $form=shift; open (my $self,$form,@_) # or Carp::cluck "can't open $form@_: $!" ; return bless $self,$class; # $self is a glob ref } sub CLOSE { #Carp::cluck "\nCLOSE: ",Data::Dumper->Dump([\@_],[qw(*_)] +),' '; my $self=shift; return close $self; } sub DESTROY { #Carp::cluck "\nDESTROY: ",Data::Dumper->Dump([\@_],[qw( +*_)]),' '; my $self=shift; $self->CLOSE; } sub EOF { #Carp::cluck "\nEOF: ",Data::Dumper->Dump([\@_],[qw(*_)]),' +'; my $self = shift; return eof $self; } sub FILENO { #Carp::cluck "\nFILENO: ",Data::Dumper->Dump([\@_],[qw(*_ +)]),' '; my $self=shift; return fileno $self; } sub OPEN { #Carp::cluck "\nOPEN: ",Data::Dumper->Dump([\@_],[qw(*_)]), +' '; my $self=shift; my $form=shift; $self->CLOSE; open($self,$form,@_) or croak "can't reopen '$form@_': $!"; return 1; } sub READLINE { #Carp::cluck "\nREADLINE: ",Data::Dumper->Dump([\@_],[q +w(*_)]),' '; my $self=shift; return undef if $self->EOF; #warn Data::Dumper->Dump([\(my $t=wantarray())],[qw(*wantarray)]), +' '; if (wantarray()) { my @a=<$self>; main::mySub(@a); return @a; } else { my $s=<$self>; main::mySub($s); return $s; }; } package main; use strict; use warnings; my $name='mydata'; tie *FOO,"MyTie"; open(FOO,'<',$name) or die "Can't open '$name' for reading. $!"; my $line=<FOO>; print "Scalar: $line"; $line=<FOO>; print "Scalar: $line"; my @array=<FOO>; print "Array: ",@array; while (<FOO>) { print "In while: $_"; } close(FOO); exit; sub mySub { warn "\nmain::mySub: ",Data::Dumper->Dump([\@_],[qw(*_)]),' '; return; }; __DATA__

    works just fine to record what is read from *FOO.

    But I need to tie a lexical filehandle so I can write

    package main; use strict; use warnings; my $name='mydata'; my $FOO; tie $FOO,"MyTie"; open($FOO,'<',$name) or die "Can't open '$name' for reading. $!"; my $line=<$FOO>; print "Scalar: $line"; $line=<$FOO>; print "Scalar: $line"; my @array=<$FOO>; print "Array: ",@array; while (<$FOO>) { print "In while: $_"; } close($FOO); exit;

    But this throws 'Can't locate object method "TIESCALAR" via package "MyTie" at ...' - where the tie is attempted. Any ideas on how to tie a lexical filehandle?

    "This is perl 5, version 20, subversion 2 (v5.20.2) built for MSWin32-x86-multi-thread-64int"

error variables after IPC::Run
4 direct replies — Read more / Contribute
by CarolinaPerler
on Jun 19, 2017 at 11:47

    Using IPC::Run.
    Would like to examine all the built-in special error variables: $@, $!, $^E, and $?. After an IPC::Run 'run', when I try to check $! and $^E, I get 'Illegal seek'.

    run (\@commandArray, \$in, \$error, timeout(3)); print "LIB LEVEL ERROR: $!\n"; print "OS LEVEL ERROR: $^E\n";

    On some systems in some situations, $^E is not supported. But, $! should be available. IPC::Run hands back $error (given the code above). But, it does not necessarily give back all the detail that can be gleaned from cruising through the built-in error vars. I like using IPC::Run and would like to continue doing so. But, need a robust mechanism for catching error info. It appears that IPC::Run is monkeying with $! and $^E. Any ideas on how to capture the error detail after an IPC::Run run call?

How to ask user for file name and save the output to a new text file
2 direct replies — Read more / Contribute
by mmazlan67
on Jun 18, 2017 at 23:36

    Hi, i am really new to Perl because before this i worked on Excel VBA. For now i have 3 different perl scripts in VNC that i plan to combine them into one.

    The first script will ask user for file name (e.g summary.txt), find the matching string in the summary.txt and saved the output in inout.txt using command on console "perl summary.txt > inout.txt". But error will occur Then, i run the second script just to take all the necessary data based on the requirement and saved the output in result.txt using command on console "perl inout.txt > result.txt. The third script will send result.txt to an email which can be viewed in Windows. I know that it is possible but i have no idea on how to do it as i got stuck on thinking how to open summary.txt file to read and open inout.txt to write at the same time.

    I add this code below in but then i cannot run the script on console using "perl summary.txt > inout.txt"

    print "Enter the name of the file: "; my $base_dir = <>; chomp($base_dir);open( my $DATA, "<" , $base_dir) or die "Can't open f +ile '$base_dir': $!"; while ( <$DATA> )

    #! /tools/perl/5.8.8/linux/bin/perl use strict; use warnings; while (<>) { if ($_ =~ /^\s\s(\S+)*delay\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+ +(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+) +/) { print "$_"; } }

    #! /tools/perl/5.8.8/linux/bin/perl use strict; use warnings; while ( <> ) { #if my ( $set ) = m/^\s+(\S+)/; #get the first word my ( $name,$value ) = m/-name (\S+) (\S+)/; #get the name and value my ( $mode ) = m/mode == (\S+)\"/; #get the mode print "$mode $name $set $value\n"; }

    #! /tools/perl/5.8.8/linux/bin/perl use strict; use warnings; my $name='inoutdata'; system("uuencode /home/user/set/result.txt | mailx -s '$name' email");
System vs. User module version of List::Util
5 direct replies — Read more / Contribute
by Lady_Aleena
on Jun 17, 2017 at 21:12

    Hello. List::Util is a core module, but the system version has not been updated since 1.27. So I installed it in my user directory, and it is version 1.47. However, I am getting an error that uniq is not exported by List::Util. According to the docs, List::Util has had uniq since version 1.45. So, what do I do to get the system to look at the user installed List::Util instead of the system installed List::Util? Is there precedence in @INC? Do I have to beg the system administrators to update their List::Util?

    I went to the command line and read the perldoc for List::Util, and perldoc brought up the docs for 1.47 not 1.27. I am confused by that a bit.

    Here is my @INC from the command line, and it has my user directories first, so that makes this even more confusing.

    Here is my @INC from the browser, and it has my user directories first, so that makes this so much more confusing.

    Any and all help is appreciated.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Log In?

What's my password?
Create A New User
[oiskuu]: ... getlogin refers to tty owner; if you close STDIN, then getlogin returns undef. I get undef in my shell (running under X)
[tye]: Then there is a more persistent big of data similar to getlogin(). I don't believe even daemonizing drops it. So you can tell services that were started at boot time from those started by a person.
[tye]: I'll have to look into that later. getlogin() suites my current needs.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-06-23 19:22 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (554 votes). Check out past polls.