Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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
INIT {$SIG{__DIE__} and Getopt::Long
3 direct replies — Read more / Contribute
by demichi
on Jul 29, 2015 at 13:16
    Hi all

    I am normally using the following line to capture the die output into a logfile.

     INIT {$SIG{__DIE__}=sub {LOG_MSG("normal",3,"GENERAL","Script died: $_[0]") and close LOG;}}

    Now I am using also Getopt::Long. I don't want to have a logfile generated if somebody is chosing the wrong parameter. Therefore I let the script die with an usage output.

    Unfortunately if somebody choses a wrong getopt parameter now - I get a log error message because of the INIT-"die" setting as the log file is not opened yet.

    G:\development\bin> -x > 4,GENERAL,Script warning: Unknown option: x print() on unopened filehandle LOG at G:\development\bin\ line 45. + ### Version:2.0.0 NAME xxx > 3,GENERAL,Script died: 1 at G:\development\bin\ line 14. ### > 4,GENERAL,Script warning: print() on unopened filehandle LOG at G:\d +evelopment\bin\ line 45. ### print() on unopened filehandle LOG at G:\development\bin\ line 45. + ### 1 at G:\development\bin\ line 14. ### G:\development\bin>

    Every line marked with "###" at the end I do not want to have as output to STDOUT.

    Do you have an ideas how can fix it? Thanks.

    kind regards de Michi

    use strict; use warnings; use Getopt::Long qw(:config no_ignore_case bundling); # Get options / my $VERSION = "2.0.0"; INIT {$SIG{__DIE__}=sub {LOG_MSG("normal",3,"GENERAL","Script died: $_ +[0]") and close LOG;}} INIT {$SIG{__WARN__}=sub {LOG_MSG("normal",4,"GENERAL","Script warning +: $_[0]")}} # Check Flags my $flag_help; my $flag_version; my $flag_config; GetOptions ( 'h|help' => \$flag_help, 'V|VER' => \$flag_version, 'c|config=s' => \$flag_config, ) or die USAGE(); # Check flags and print usage if ($flag_version) { print "Version: $VERSION\n"; exit; } if ($flag_help) { USAGE(); exit; } open(LOG,"> SCRIPTLOG_FILE") or die ("Can't open SCRIPTLOG_FILE: $!\n" +); close LOG; ### subs sub LOG_MSG { my $par_LEVEL = shift (@_); my $par_SEVERITY = shift (@_); my $par_FUNCTION = shift (@_); my @line = @_; print "> $par_SEVERITY,$par_FUNCTION,@line\n"; print LOG "$par_SEVERITY,$par_FUNCTION,@line\n"; } sub USAGE { my ($message)=<<'MESSAGE'; NAME xxx MESSAGE print "Version:${VERSION}\n$message"; }
Consistent xml formatting
1 direct reply — Read more / Contribute
by Haloric
on Jul 28, 2015 at 10:05

    Hi Monks,

    I have many xml files that I am attempting to compare with either XML::SemanticDiff or XML::SemanticCompare.

    Is there a way to get the XML ordered in a consistent way before I start this comparison, without calling out to a separate tool. They both get confused by slight ordering changes

    For example, I have elements that are

    <sequence name="b" .. <sequence name="a" .. <sequence name="c" ..

    I would like them ordered by the 'name' attribute before the comparison starts.

    I have looked at XML::LibXML::PrettyPrint but can't make it do what I want.

    I can see SemanticDiff copes with missing attributes, but not sure how it would cope with a missing '<sequence name="b" ' element all together without thinking it was a difference in attribute value, rather than entirely missing.


How to call a perl function without its context?
8 direct replies — Read more / Contribute
by kitomer
on Jul 28, 2015 at 05:34
    I want to call a Perl function and be sure it cannot access any variables declared in its context, just its local variables and passed arguments. Is this possible?
Performance of assambled regex
6 direct replies — Read more / Contribute
by Foodeywo
on Jul 26, 2015 at 08:04
    Dear Monks,

    today I re-stumbled upon an issue I quick-and-dirty solved a while ago but I want to solve it more elegantly while I am doing code polishing these days.

    I use Regexp::Assemble to assemble regex that are about 15kb to 87kb large. Now I very simply run through a large (~10GB) file and match the regex. I used to do this on the command line in the style

    perl -ne 'print if (/MYLARGEREGEX_HERE/../END_OF_BLOCK/)' inputfile > +outputfile

    this was fast as hell. However when my regex grew in size, I was not able to copy paste them into the bash so I started to read the regex from a file and did something like this

    #!perl use strict; use warnings; open my $fh_big_file, '<', $ARGV[0] || die; #first argument must be th +e input file open my $fh_regex, '<', $ARGV[1] || die; # second argument points to t +he file containing the regex my $regex = <$fh_regex>; while(<$fh_big_file>) { print if (/$regex/../^END_OF_BLOCK/); }

    The funny thing is, that this flavour of code costs me factor 20 in speed or even more. I can reclaim the speed by avoiding to store the regex in a variable, e.g.

    while(<$fh_big_file>) { print if (/MY_HUGE_REGEX_JUST_PLAIN/../^END_OF_BLOCK/); }

    so I assume this has something to do with fetching the content of the variable (from RAM to CPU?) over and over for each loop of while(<>), whereas inputing the regex directly doesnt need to re-read it every time.

    This approach however requires me to manually copy the regex to its place each time I run the whole procedure of "assembling, searching, processing, assembling, seachring, processing" and I would like to automize it without loss of performance. Any ideas?

    thanks and cheers!


    The suggestion to use the o operator works. However it needs to be behind /$regex/ not behind /END_OF_BLOCK/. i.e. like shmem suggested:

    while(<$fh_big_file>) { print if (/$regex/o .. /^END_OF_BLOCK/); }


Pack + Fat32 timestamp
2 direct replies — Read more / Contribute
by tbr123psu
on Jul 25, 2015 at 18:06

    esteemed monks:

    greetings all! i've been struggling with this for days now, and figured it was finally time to ask for some help.

    I've been following the instructions found at to set up a wifi SD card for use in a photoframe. I wanted to use Perl rather than the python referenced on the page because I generally prefer perl and because i kinda wanted to do it myself.

    it's been smooth sailing, right up to the point of having to submit a FAT32 timestamp to set the creation date of the uploaded file. This part has me completely stumped.

    i've been all over google, and the best reference I can find about the required formats is from this thread on stackoverflow: There's no search results here for fat32.

    interestingly enough, I was able to figure out how interpret the dates coming off the card (for the purposes of knowing which photos were the last ones added, so I can only upload new ones), but trying to apply the same logic in reverse did not work so well. I'm also not entirely clear on why it worked the way it did, such that they come out split up but when going in, the card wants just one string, but I suppose that's just quirkiness in the API i've got to live with.

    anyhow, i suspect the answer has something to do with pack, but i won't lie, i'm just flinging stuff at the wall in the hopes that it sticks. I thought i was making progress, in that I have some idea what the actual value for a current timestamp is that would be submitted to the api call (through trial and error/guesswork -- manually trying to make things up, based on the example given in the API documentation

    so i've got some idea what the value needs to look like, but for the life of me i can't get that output to generate programatically. it seems that it's inclusive of 0-9 and a-f, so it seems like a hexadecimal number (as per, but being honest, this gets a little deeper than i usually go. thinking about it sometimes makes my head hurt.

    has anyone ever bumped into anything like this before or can offer any insight? code snippets below that do the relevant stuff with dates/times.

    here's the code that pulls the time and date from the card and interprets it.

    #Each row of the list is returned in the following format. #<directory>, <filename>, <size>, <attribute>, <date>, <time> # date 16 bit int -- bit 15-9 value based on 0 as 1980, bit 8-5 month +value from 1 to 12, bit 4-0 day, value from 1 to 31 # time 16 bit int -- bit 15-11 hour, 10-5, minute, 4-0 second / 2 # size my $fileList = getHttp($cardip, "command.cgi?op=100&DIR=/"); #print ($fileList . "\n"); my @fileArray = split("\n", $fileList); my @fileTimesArray; my $lastTime = 0; print (ref(@fileArray) . "\n"); foreach my $file (@fileArray) { if (index($file, ",") != -1) { print "working with file $file\n"; my ($directory, $name, $size, $att, $date, $time) = split(",", + $file); # example date, time = 18151,39092 my $day = ($date >> 0) & (2**5-1); my $month = ($date >> 5) & (2**4-1); my $year = ($date >> 9) & (2**7-1); $year = 1980 + $year; my $second = ($time >> 0) & (2**5-1); my $minute = ($time >> 5) & (2**6-1); my $hour = ($time >> 11) & (2**5-1); $second = $second * 2; print ("file: $name | $month - $day - $year | $hour : $minute +: $second | $epochTime\n"); #print ("file: $name | $date | $time\n"); #print ("day: $day\n"); #print ("month: $month\n"); #print ("year: $year\n"); #print ("second: $second\n"); #print ("minute: $minute\n"); #print ("hour: $hour\n"); my $perlMonth = $month - 1; my $epochTime = timelocal($second,$minute,$hour,$day,$perlMont +h,$year); if ($epochTime > $lastTime) { $lastTime = $epochTime; } push @fileTimesArray, { file => $name, epoch => $epochTime, si +ze => $size }; } }

    and here's the code for trying to generate a timestamp based on the timestamp returned from the file on disk.

    @info = stat($path->{file}); my $createdtime = $info[10]; print "regular created time is: $createdtime\n"; my ($sec, $min, $hour, $day,$month,$year) = (localtime($createdtim +e))[0,1,2,3,4,5]; # You can use 'gmtime' for GMT/UTC dates instead of 'localtime' $month++; my $displayYear = $year; my $realYear = $year; $year = $year - 80; $second = ceil($sec / 2); # example date, time = 18151,39092 --> not same format!?! # time 16 bit int -- bit 15-11 hour, 10-5, minute, 4-0 second / 2 #my $encSecond = $second & (2**5-1); #my $encMinute = $minute & (2**6-1); #my $encHour = $hour & (2**5-1); # date 16 bit int -- bit 15-9 value based on 0 as 1980, bit 8-5 mo +nth value from 1 to 12, bit 4-0 day, value from 1 to 31 #my $encDay = $day & (2**5-1); #my $encMonth = $month & (2**4-1); #my $encYear = $month & (2**7-1); #use integer; my $data = $year . $month . $day . $hour . $min . $second; print "using $data as input for pack\n"; #my $data = $second . " " . $minute . " " . $hour . " " . $day . " + " . $month . " " . $year; #my $createdtimeFat = pack "N8", $data; my $createdtimeFat = pack "N8", $year,$month,$day,$hour,$min,$sec +ond; #my $createdtimeFat = ($year << 25) | ($month << 21) | ($day << 1 +6) | ($hour << 11) | ($min << 5) | ($second << 0); #my $createdtimeFat = (($year & (2**7-1)) << 25) | (($month & (2* +*4-1)) << 21) | (($day & (2**5-1)) << 16) | (($hour & (2**5-1)) << 11 +) | (($min & (2**6-1)) << 5) | (($second & (2**5-1)) << 0); # 8 digits # 8 = year # 7 = year + month # 6 = month + day # 5 = day #### # 4 = hour # 3 = hour + month # 2 = minute + second # 4 = second #my $createdtimeFat = '469f9f01'; #my $hex = sprintf("0x%x", $createdtimeFat); #my $hex = printf("%x",$createdtimeFat); print "Unix time ".$createdtime." converts to ".$month." ".$day.", + ".($displayYear+1900)." ".$hour.":".$min.":".$sec." year (in offset +from 1980) is $year [real year is $realYear]\n"; #print $encSecond ." ". $encMinute ." ". $encHour ." ". $encDay ." + ". $encMonth ." ". $encYear . "\n"; print "createdtimeFat should look something like 46ef99c6\n"; print "createdtimeFat is $createdtimeFat\n"; my @unpacked = unpack("N8",$createdtimeFat); print "and unpacked: " . @unpacked . "\n"; my $setdate = getHttp($cardip, "upload.cgi?FTIME=0x" . $createdtim +eFat); print "result of setdate operation: $setdate\n";

    and this is the getHttp function/sub

    sub getHttp() { my $ip = shift; my $args = shift; my $status; my $url = "http://" . $ip . "/" . $args; #print ("accessing " . $url . "\n"); # set custom HTTP request header fields my $req = HTTP::Request->new(GET => $url); my $resp = $ua->request($req); if ($resp->is_success) { my $message = $resp->decoded_content; #print "Received reply: $message\n"; $status = $resp->decoded_content; } else { print "HTTP GET error code: ", $resp->code, "\n"; print "HTTP GET error message: ", $resp->message, "\n"; $status = $resp->message; } return $status }

    many thanks in advance for any help or guidance anyone can offer - i'm at wit's end, and i feel like i've got to be missing something!

ssl details cgi script
3 direct replies — Read more / Contribute
by alokranjan
on Jul 25, 2015 at 15:04
    Hi All, Can anyone please have a look at my cgi script to print the ssl certificate expirt date. I am picking the sitename from a html page and passing to the below cgi:
    use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use Net::SSL::ExpireDate; use strict; my $sitename; my $ed; my $expire_date; print header; print start_html("Thank You"); print h2("Thank You"); my %form; foreach my $p (param()) { $form{$p} = param($p); print "$p = $form{$p}<br>\n"; $sitename = $form{$p}; } #$sitename = ""; chomp($sitename); $sitename =~ s/^\s+|\s+$//g; print "\nWebsite name is: $sitename.\n"; $ed = Net::SSL::ExpireDate->new( https => $sitename ); if (defined $ed->expire_date) { $expire_date = $ed->expire_date; print "$expire_date\n"; } print end_html;
    I am wondering why its not working, though a separate Perl script is working fine to get the expiry date. Any help/assistance would be highly appreciated.

    Thanks, Alok

Getting constructor caller in Mo/Moo/Moose BUILD/BUILDARGS
2 direct replies — Read more / Contribute
by perlancar
on Jul 25, 2015 at 07:58

    What is the proper way to get the caller to our object creation (the object's client code) inside Mo/Moo/Moose's BUILD or BUILDARGS? I'm okay with getting a subclass.

    From a quick glance of the Moo and Moose codebase, it doesn't seem like Moo/Moose provides a utility routine for this. A quick search on CPAN also doesn't yield anything yet.


    package Class1; use Moo; has attr1 => (is => 'rw'); sub BUILD { no strict 'refs'; my $self = shift; # XXX set default for attr1 depending on the caller unless (defined $self->attr1) { $self->attr1(${"$object_caller_package\::FOO"}); } } package C2; use Moo; extends 'C1'; package main; our $FOO = 42; say C2->new->attr1; # prints 42

    In principle it should be easy enough to loop over the caller stack and use the first non-Moo* stuff.

RFC: Name and/or API for module ("HTML::RewriteURLs")
5 direct replies — Read more / Contribute
by Corion
on Jul 25, 2015 at 05:45

    Once again, I have a module but no name. I come here in the hope of finding a good name that helps others find this module and put it to good use.

    Let me first describe what the module does:

    The module exports two functions, rewrite_html and rewrite_css. These functions rewrite all things that look like URLs to be relative to a given base URL. This is of interest when you're converting scraped HTML to self-contained static files. The usage is:

    use HTML::RewriteURLs; my $html = <<HTML; <html> <head> <link rel="stylesheet" src="http://localhost:5000/css/site.css" /> </head> <body> <a href="">Go to</a> <a href="http://localhost:5000">Go to home page/a> </body> </html> HTML my $local_html = rewrite_html( "http://localhost:5000/about", $html ); print $local_html; __END__ <html> <head> <link rel="stylesheet" src="../css/site.css" /> </head> <body> <a href="">Go to</a> <a href="..">Go to home page/a> </body> </html>

    The current name for the module is HTML::RewriteURLs, and this name is bad because the module does not allow or support arbitrary URL rewriting but only rewrites URLs relative to a given URL. The functions are also badly named, because rewrite_html doesn't rewrite the HTML but it makes URLs relative to a given base. And the HTML::RewriteURLs name is also bad/not comprehensive because the module also supports rewriting CSS.

    I'm willing to stay with the HTML:: namespace because nobody really cares about CSS before caring about HTML.

    I think a better name could be HTML::RelativeURLs, but I'm not sure if other people have the same association. The functions could be renamed to relative_urls_html() and relative_urls_css().

    Another name could be URL::Relative or something like that, but that shifts the focus away from the documents I'm mistreating to the URLs. I'm not sure what people look for first.

    Below is the ugly, ugly regular expression I use for munging the HTML. I know and accept that this regex won't handle all edge cases, but seeing that there is no HTML rewriting module on CPAN at all, I think I'll first release a simpleminded version of what I need before I cater to the edge cases. I'm not fond of using HTML::TreeParser because it will rewrite the document structure of the scraped pages and the only change I want is the change in the URL attributes.

    =head2 C<< rewrite_html >> Rewrites all HTML links to be relative to the given URL. This only rewrites things that look like C<< src= >> and C<< href= >> attri +butes. Unquoted attributes will not be rewritten. This should be fixed. =cut sub rewrite_html { my($url, $html)= @_; $url = URI::URL->new( $url ); #croak "Can only rewrite relative to an absolute URL!" # unless $url->is_absolute; # Rewrite relative to absolute rewrite_html_inplace( $url, $html ); $html } sub rewrite_html_inplace { my $url = shift; $url = URI::URL->new( $url ); #croak "Can only rewrite relative to an absolute URL!" # unless $url->is_absolute; # Rewrite relative to absolute $_[0] =~ s!((?:src|href)\s*=\s*(["']))(.+?)\2!$1 . relative_url(UR +I::URL->new( $url ),"$3") . $2!ge; }

    Update: Now released as HTML::Rebase, thanks for the discussion and improvements!

Convert GMT timestamp to EST/EDT
3 direct replies — Read more / Contribute
by gtk
on Jul 25, 2015 at 01:45
    Is there a simple way to convert GMT timestamp to EST/EDT(any timezone) timestamp without using new additional Perl Libraries? Sample of my file(Time in GMT and I wanted to view the time in EDT or EST):
    20150619-17:30:43.616, 26
    20150619-17:30:33.442, 23
    20150619-17:30:40.376, 26
    20150619-17:30:38.863, 26
    20150619-17:30:56.936, 26
    20150619-17:30:34.952, 24
    20150619-17:30:45.889, 26
    20150619-17:30:53.940, 23
    20150619-17:30:51.154, 25
    20150619-17:30:48.699, 26
ambiguous regex match
3 direct replies — Read more / Contribute
by Hosen1989
on Jul 24, 2015 at 12:26

    Dear ALL,

    I was doing some parsing for log file and come to this bug (i think), I add the next simple code to show you what I face:

    use strict; use warnings; my $data = 'blabla;tag1=12345;blabla;'; # my $data = 'blabla;tag1=12345;blabla;tag2=99999'; # get tag1 value $data =~ m/tag1=(\d+)/g; my $tag1 = $1; # get tag2 value $data =~ m/tag2=(\d+)/g; my $tag2 = $1; print "tag1 = $tag1\n"; print "tag2 = $tag2\n";

    The output:

    tag1 = 12345 tag2 = 12345

    Us you can see the are only tag1 value in $data, so should be no match and the second tag $tag2 should be undefined,

    but what i got is  $tag1 =$tag2!!!.

    So can any monk here (and pretty please) explain to my what happen here.



Variable blasphemy
4 direct replies — Read more / Contribute
by SixTheCat
on Jul 24, 2015 at 10:40
    Oh monks of the Holy Order of Perl. I bring grave news of blasphemy in my variables! I am new to perl (only a week in) so it's very likely a problem with me but... I'm trying to write a simple script to open a csv file and get two columns which are then used to convert one name to the other. The problem is that while the line is read correctly from the file and seems to separate correctly using the split function, the variables themselves act wonky after. If I print (or say) both of the variables in the same string, if one variable is displayed first the string displays fine but if the other is output first, it doesn't show up. I don't see any possible hidden terminating characters in the CSV file that would cause this problem. Any ideas? The csv file contains the following data:



    The output looks something like this

    --------- Converting Star Allele references to rs numbers ---------

    Current input line is

    Index 0 is rs6413438

    Index 0 is rs6413438 is stored as rs6413438 <-- Correct display

    Index 1 is CYP2C19_10

    Index 1 is CYP2C19_10

    is stored as CYP2C19_10 <--- WTF, where is the first variable?

    Comparing CYP2C19_10

    and CYP2C19_10

    Comparing CYP2C19_10

    and CYP2C19_12

    Current input line is

    Index 0 is rs4986910

    Index 0 is rs4986910 is stored as rs4986910 <-- Correct display

    Index 1 is CYP2C19_20

    Index 1 is CYP2C19_20

    is stored as CYP2C19_20 <--- WTF

    Comparing CYP2C19_20

    and CYP2C19_10

    Comparing CYP2C19_20

    and CYP2C19_12

    -------------- Done converting Star Allele references -------------

    #!perl use strict; use 5.010; my $STARFile; + # File handle to reference file my @Stars; $Stars[0] = "CYP2C19_10"; + # Mock array of values to cross reference $Stars[1] = "CYP2C19_12"; + # if(@Stars==0){return;} + # If no Star Alleles were specified then no n +eed to do this so return to the main body if(! open $STARFile,"<","test.csv"){die "Reference file could not be f +ound or could not be opened.";} # Open the Star reference file to +prepare to convert information and store the file handle to $STARFile +. print "Converting specified Star Designations to SNPs..."; # The conversion table is opened so convert the Star name to rs number +s and then store the rs numbers to the @SNPs array and the correspond +ing Star name to the @Stars array at the same index. my @SNPs; my @StarsCon; my $RefIndex; + # Holds the line in the reference table file my $StarIndex; + # Holds the index of the @Stars Array that is + being checked my $tmpSNPIndex; + # Holds the index in the @SNPs array that we ar +e comparing my $tmpStar; + # Holds the Star Allele name my $tmpRS; + # Holds the SNP's rs number my @tmpConv; + # Holds the split Star and rs numbers say "\n--------- Converting Star Allele references to rs numbers ----- +----"; while (<$STARFile>){ + # Input a line from the database and as long a +s we haven't reached the end of the file chomp; + # Remove the trailing newline say "Current input line is @_"; @tmpConv = split ",",$_; + # Split the CSV line from the reference table s +uch that @tmpConv[0] = Star name and @tmpConv[1] = rs number $tmpStar = $tmpConv [1]; $tmpRS = $tmpConv[0]; say "Index 0 is $tmpConv[0]"; + # Displays correctly say "Index 0 is $tmpConv[0] is stored as $tmpRS"; + # Displays correctly say "Index 1 is $tmpConv[1]"; + # Displays correctly say "Index 1 is $tmpConv[1] is stored as $tmpStar"; + # Displays INcorrectly for($StarIndex=0;$StarIndex<@Stars;$StarIndex++){ say "Comparing $tmpStar and $Stars[$StarIndex]"; if($tmpStar eq $Stars[$StarIndex]){ + # If the current line of the database file c +ontains the Star Allele rs number then $tmpSNPIndex = @SNPs; + # Get the number of entries in the @SNPs array +. say "1. $tmpRS was converted from $tmpStar"; say "2. $tmpStar was converted to $tmpRS"; say "3. $tmpStar was converted to $tmpRS"; say "4. $tmpRS was converted from $tmpStar"; push @StarsCon, $tmpStar; + # Add the Star allele name to the @StarsCon ar +ray push @SNPs, $tmpRS; + # Add the new rs number to the @SNPs array if(@Stars>0){ + # If we have more than one SNP then splice @Stars,$StarIndex,1; + # and @Stars array }else{ + # Otherwise Pop off the last one pop @Stars; + # } last; + # Exit the for loop } } if(! @Stars>0){last;} + # If that was the last entry then stop searchi +ng } say "-------------- Done converting Star Allele references ----------- +--"; if(@Stars>0){ + # If any SNPs have not been found then say "\n"."Conversions not completed: @Stars."; + # Inform the user which ones were not found }else{ + # Otherwise say "\n"."All conversions successful."; + # Inform the user that all were found } close $STARFile; + # Close the reference file print "Done!\n";
Copying an ascii text file, replicating end of line terminator (windows or unix)
4 direct replies — Read more / Contribute
by luckycat
on Jul 24, 2015 at 04:23
    I've written a Perl script which runs in linux that copies an ascii text file to a new file, line terminators could be Windows style (\r\n) or Unix (\n). On certain lines which match a string I'm looking for I will process them before outputting that line back to the new file. On lines I don't process, doing a simple print OUTFILE $_; works great as it'll just replicate whatever line terminator the line uses and write that out to the output file. But for the lines I'm processing, I need to write back my processed line back out to it so I need to add in the line terminator manually. I'm doing this check right now:
    my $endofline = ( /\r\n$/ ) ? "\r\n" : "\n";
    Then here's the code for the processed line I'd write out:
    print OUTFILE "$processed_string","$endofline";
    My script works but I'm wondering if there's a better, cleaner way to do this? Currently I'm doing the end of line check within the while loop that processes each line of the input file so every single line is checked which is probably not efficient. I wanted to guard against the case where you could possibly have mixed windows and unix end of line terminators in the same file. However if that's extremely rare I guess I could remove the check from within the while loop that processes each line of the input file. If I do that, how would I get the type of line terminator the file uses so I know what to use in the print statement later? Basically is there a better way to do what I'm trying to do. Thanks for any tips.
New Meditations
Time for an application portfolio
7 direct replies — Read more / Contribute
by talexb
on Jul 27, 2015 at 12:04

    I have been tinkering with a few tools lately, and now want to put up a portfolio of some web applications that I am working on. I have an account on pair Networks (they also host this site), so I set up local::lib and went ahead and tried to install Mojolicious::Lite, since that's the platform I'm working on these days.

    No dice -- Mojo::Lite requires 5.10, and pair only has 5.8.9. I checked with the other provider I use, and they have 5.8.8.

    So the two options I can see are a) install an up-to-date Perl on one of those accounts, or b) have these web applications run on my home machine (perhaps using to provide consistent name resolution -- not sure is this is still available).

    I could go find another web provider, but that's additional expense, and not really my best option right now. Feedback welcome!

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

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 studying the Monastery: (14)
As of 2015-07-29 18:38 GMT
Find Nodes?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

    Results (267 votes), past polls