Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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
Match all Non-0 and Letters
6 direct replies — Read more / Contribute
by arblargan
on Jun 24, 2017 at 03:05

    I'm relatively new to Perl and am having a terribly difficult time figuring this one out. I'm expecting a string in the following format:

     00000001

    Essentially, a normal word will be 7 0's followed by a number between 0-9 (8-digits total). However, occasionally there is corruption in the file being processed, causing the format to have something like the following:

     FFFFFFFF or  6C163512

    I want to skip these lines of corruption and loop until the corruption has been passed. This is where the tricky part comes in (at least for me). I have tried every combination of matching I can think of, but can't seem to get this one squared away. Below are the lines of code I have tried:

    $Disc = get_word(); $D1 = substr($Disc,0,7); $D2 = substr($Disc,7,1); if ($D1 !~ /0+/ and $D2 !~ /([0-9]+)/) ##Catches FFFFFFFF just fine, b +ut not 6C163512 #### $D1 = 6C16351 and $D2 = 2 ###Get words until corruption is cleared. Works great with FFFFFFF +F, but will not catch 6C163512 if ($D1 !~ /0000000/ and $D2 !~ /\D/) ## Same as above ###Get words until corruption is cleared. Works great with FFFFFFF +F, but will not catch 6C163512 if ($Disc =~ /[1-9a-ZA-Z]{7}\D/ ## Same as above ###Get words until corruption is cleared. Works great with FFFFFFF +F, but will not catch 6C163512

    I've been working on this forever and can't seem to figure out how to dynamically catch this corruption in the event that all F's have migrated from the string word. I created the $D1 and $D2 variables to try and see why the regex patterns weren't matching, but I still can't figure it out.

    Lastly, it should be noted that occasionally, the line of corruption will show as 01020102. The corruption value will be dynamic. This is why I simply can't use /\D+/ for the majority of the string as the first 7 digits must be 0 for a valid word.

Generate a report for every month for a year
3 direct replies — Read more / Contribute
by younggrasshopper13
on Jun 23, 2017 at 16:10
    Hey guys! I have a perl script that I use generate billing reports that gets ran and emailed every month via cronjob to report on some metrics. The perl script runs fine (I originally got this working because of some help from the wonderful monks!) For security reasons I cannot post the script itself but I can post how the current date filter works:
    y $START_DATE = `date '+%Y-%m-%d' -d "-1 month"`; my $END_DATE = `date '+%Y-%m-%d'`; chomp $START_DATE; chomp $END_DATE; my $URL = "http://url/url/url/dump?end_date=$END_DATE&start_date=$STAR +T_DATE&type=csv";
    What I need to do is setup this script to generate a monthly report every month for past 2 years. Is there any easy way to do this with the $START_DATE and $END_DATE? Can anyone help me do this?
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 ./x.pl 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,

    Simon

    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.

    Thanks!

    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,1.1.1.1,00000C123456, hostb,2.2.2.2,00000C123457, hostc,3.3.3.3,00000C123458, hostd,4.4.4.4,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>,1.1.1.1</HOST_IP> <HOST_MAC>00000C123456</HOST_MAC> . . File 2 . <HOST_NAME>hostb</HOST_NAME> <HOST_IP>,2.2.2.2</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:

    >hsa_circ_0000001|chr1:1080738-1080845-|None|None

    ATGGGGTTGGGTCAGCCGTGCGGTCAGGTCAGGTCGGCCATGAGGTCAGGTGGGGTCGGCCATGAAGGTGGTGGGGGTCATGAGGTCACAAGGGGGTCGGCCATGTG

    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?

    Pete.

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:

    Washington
    New York
    Louisiana
    Georgia
    Texas
    Iowa
    etc.

    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

    Ave,

    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?

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2017-06-26 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (577 votes). Check out past polls.