Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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
Perl 6 on Windows 10
No replies — Read more | Post response
by CountZero
on Oct 10, 2015 at 14:34
    I just downloaded a recent version of Rakudo * (Rakudo 2015.6; MoarVM 2015.6) on my Windows 10 computer.

    When I try to run Perl 6 I get the error message "This version of MoarVM is not compatible with this version of Windows".

    Did anyone manage to get Perl6 working on Windows 10 yet?


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
CMS based Mojolicious
No replies — Read more | Post response
by morning_cat
on Oct 10, 2015 at 11:06
reference to an undefined key
2 direct replies — Read more / Contribute
by exilepanda
on Oct 10, 2015 at 08:20
    Hello monks,

    Sorry I believe I have given a pretty poor title but I really can't think of any better one, and I think this is the fact though. I'd like to know if there's any chance I can have such code candies ?

    my $obj = bless { Root => $rootDir, UserDir => $obj->{Root} . "Usr/$userId/", UserAppData = $obj->{UserDir} . "$appName/", }, shift; # of cause this won't work
    instead of :
    $obj = bless { Root => $rootDir, UserDir => undef, UserAppData => undef, }, shift; $obj->{UserDir} = $obj->{Root} . "Usr/$userId"; $obj->{UserAppData} = $obj->{UserDir} . "$appName";
    In fact I have much more paths that I need to defined while the object is created, but I hope to state the logic of the properties in clear at the first place.

    I guess I am out of luck but still trying to ask because when the interpreter read {Root}, that should be some place already stored the value ( but I juz don't know how to ref to it), no?


    I know why it's not working, what I try to emphasize is only inside the hash, so please forgive I didn't manage to give good code about the before and after.

    Though, I suddenly recalled something ( thank you very much for all you guys' feedback ). Yrs ago, I wrote a module for interpret an INI config file. Which accepts things like this:

    [ConfigDirs] A = /some/dir B = /_#A#_/DeeperDir C = /_#B#_/EvenDeeperDir
    And my module will go through it line by line. Every key recorded can be used by the next line. Regex will replace the _#*#_ with a proper recorded key's value. So it Data::Dump will produce something like
    $var = { 'ConfigDirs' => { 'A'=> '/some/dir', 'B'=> '/some/dir/DeeperDir', 'C'=> '/some/dir/DeeperDir/EvenDeeperDir' } }
    Now the questions can be added are: 1) is there any existing module deal's something like that? 2) is there any threat I elaborating things in this way?

    As I am going to reuse this module's code to let me accept params as I originally proposed.

optgroup with Perl CGI
1 direct reply — Read more / Contribute
by alokranjan
on Oct 10, 2015 at 07:30
    Hi All,

    I have a folder "items" under which I have files like: fruit and animal containing the names of fruits and animals respectively. Now I want to use optgroup select option.

    #!/usr/bin/perl print "Content-Type: text/html\n\n"; my @filename = split("\n", `ls items`); print <<HTML <html> <body> <select> HTML foreach(@filename){ print <<HTML <optgroup label="$_"> HTML open my $info, "items/$_" or die "Could not open $_: $!"; while( my $line = <$info>) { print <<HTML <option value="$line">$line</option> HTML } } print <<HTML </optgroup> </select> </body> </html> HTML
    Can anyone please suggest me what went wrong. Many thanks in advance !!

    Regards, Alok

Is there a way to open a memory file with binmode :raw?
2 direct replies — Read more / Contribute
by stevieb
on Oct 09, 2015 at 16:54

    Instead of using a temporary disk file, I thought I'd try to use a memory file (scalar ref), but I need to be able to use the handle with binmode $fh, ':raw' (or equivalent). Is this possible?

    use strict; use warnings; my $mf; my $fh; # mem write open $fh, '>', \$mf or die $!; print $fh "hello\n"; close $fh; # mem read open $fh, '<', \$mf or die $!; binmode $fh, ':raw'; while (<$fh>){ print "mem: " . (unpack "H*", $_) . "\n"; } close $fh; # file write open $fh, '>', 'file.txt' or die $!; print $fh "hello\n"; close $fh; # file read open $fh, '<', 'file.txt' or die $!; binmode $fh, ':raw'; while (<$fh>){ print "file: " . (unpack "H*", $_) . "\n"; }

    Output... note the difference after the 'f'. I need the mem file to reflect that of :raw like the value for file.

    mem: 68656c6c6f0a file: 68656c6c6f0d0a
CPAN on El Capitan
6 direct replies — Read more / Contribute
by rhumbliner
on Oct 09, 2015 at 11:58
    Apple's newest release of OS X, El Capitan, includes a security feature that hobbles some of the capabilities of root: SIP. This includes preventing root from changing /usr/bin. This also prevents cpan from installing a new version of CPAN as seen here:
    {s10:~} whoami root {s10:~} cpan CPAN CPAN: Storable loaded ok (v2.41) Reading '/var/root/.cpan/Metadata' Database was generated on Thu, 08 Oct 2015 10:41:02 GMT Running install for module 'CPAN' Running make for A/AN/ANDK/CPAN-2.10.tar.gz CPAN: Digest::SHA loaded ok (v5.84_01) CPAN: Compress::Zlib loaded ok (v2.069) Checksum for /var/root/.cpan/sources/authors/id/A/AN/ANDK/CPAN-2.10.ta +r.gz ok CPAN: File::Temp loaded ok (v0.23) CPAN: Parse::CPAN::Meta loaded ok (v1.4417) CPAN: CPAN::Meta loaded ok (v2.150005) CPAN: Module::CoreList loaded ok (v3.03) Building A/AN/ANDK/CPAN-2.10.tar.gz Checking if your kit is complete... Looks good Generating a Unix-style Makefile Writing Makefile for CPAN Writing MYMETA.yml and MYMETA.json <snip> All tests successful. Files=30, Tests=701, 28 wallclock secs ( 0.39 usr 0.06 sys + 18.83 cu +sr 3.16 csys = 22.44 CPU) Result: PASS ANDK/CPAN-2.10.tar.gz /usr/bin/make test -- OK Running make install Manifying 2 pod documents Manifying 16 pod documents !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!! ERROR: Can't create '/usr/bin' Do not have write permissions on '/usr/bin' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!! at -e line 1. make: *** [pure_perl_install] Error 1 ANDK/CPAN-2.10.tar.gz /usr/bin/make install -- NOT OK {s10:~}

    I'm looking for suggestions on how to best work around this. It is possible to disable SIP but I'd prefer not to.


[Resolved] strange list operator
5 direct replies — Read more / Contribute
by xiaoyafeng
on Oct 09, 2015 at 04:25
    I found the list operator(..) in 32bit perl is very mysterious. Take a look below codes:
    #1: perl -E"my @aa = 1..20_000_000; my @bb = 1..20_000_000;" #error! out o +f memory! #2: perl -E"my @aa = 1..20_000_000; my @bb = @aa;" #works well #3: perl -e"my @cc = 1..40_000_000" #error! out of memory #4: perl -E"my @cc; for(my $i = 1; $i<40_000_001; $i++){ push @cc, $i;} pr +int scalar @cc" #works well. #5: perl -e"push @cc,$_ for 1..40_000_000; print scalar @cc;" works well
    Could anyone tell me how implement range operator in perl source? I can't figure out how example 1 and 4 is broken.

    UPDATE1: add example 5

    UPDATE2: choroba perfectly answer my question, thankss

    I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

[Linux] Controlling 32-bit mode vs 64-bit mode
1 direct reply — Read more / Contribute
by syphilis
on Oct 09, 2015 at 01:58
    When I first built perl on a powerpc64 box (running Debian Wheezy) it built perl in 32-bit mode - ivtype of int, ivsize of 4, ptrsize of 4.
    But I wanted a 64-bit perl, and I discovered I could achieve that by simply adding -Dcc="gcc -m64" to the configure args I had used.
    That worked fine - perl then had ivtype of long, ivsize of 8 and ptrsize of 8.

    However, did I choose the correct way of forcing 64-bit mode ? I've always been a bit concerned that the "-m64" should be in cflags, not part of the name of the compiler.
    And, although that approach has worked fine for me for the last couple of years, I'm striking a problem compiling the (optional) gfortran elements in the PDL (perl) module ... and I'm beginning to think that problem might be due to the presence of "-m64" in $Config{cc}.

    If I have chosen the wrong means to the end, then what's the correct/recommended means ?

Why is this comparison failing?
3 direct replies — Read more / Contribute
by johnrcomeau
on Oct 08, 2015 at 14:29
    My code is doing something I really can't understand. I'm performing some linear interpolation, and test the result against the number 75. I can get two different results depending on where the &adjust_hue subroutine is called. Here's the code
    use strict; use constant HUE_RANGE => 255; my @HUES = ( 0, 25, 50, 75, 120, 168, 195, 240, + 268, 315); # 0.0 0.1 0.2 0.3 0.4 0.5 + 0.6 0.7 0.8 0.9 1.0 &adjust_hue(0.3); my @hues = (0 .. 4); $_ *= 0.1 for @hues; for (@hues) { &adjust_hue($_); } sub adjust_hue { my ($scale) = @_; my @hues = @HUES; push @hues, HUE_RANGE unless $hues[-1] == HUE_RANGE; # warn 'hues ', Dumper \@hues; # warn "n hues ", (scalar @hues), "\n"; my $n_unique_hues = -1 + scalar @hues; my $scaled_index = $scale*$n_unique_hues; my $index = int $scaled_index; my $adjusted_hue = $hues[$index] + ($scaled_index - $index)*($hues +[$index + 1] - $hues[$index]); # $adjusted_hue = eval $adjusted_hue; # This shouldn't be necessary +. Somehow this sub was producing strings instead of numbers. Later, t +his strings would fail comparisons. if ($adjusted_hue == 75) { warn " adjusted_hue ($adjusted_hue) equals 75\n"; } else { warn " adjusted_hue ($adjusted_hue) does not equal 75\n"; } warn "scale $scale, scaled_index $scaled_index, index $index, adju +sted_hue $adjusted_hue\n\n"; $adjusted_hue; }
    The output is the following for me:
    adjusted_hue (75) equals 75 scale 0.3, scaled_index 3, index 3, adjusted_hue 75 adjusted_hue (0) does not equal 75 scale 0, scaled_index 0, index 0, adjusted_hue 0 adjusted_hue (25) does not equal 75 scale 0.1, scaled_index 1, index 1, adjusted_hue 25 adjusted_hue (50) does not equal 75 scale 0.2, scaled_index 2, index 2, adjusted_hue 50 adjusted_hue (75) does not equal 75 scale 0.3, scaled_index 3, index 3, adjusted_hue 75 adjusted_hue (120) does not equal 75 scale 0.4, scaled_index 4, index 4, adjusted_hue 120
    I really don't understand why the comparison to 75 is true in one case with the parameter 0.3 and false also with the parameter 0.3 Thanks, John
Help tracking changes in array
4 direct replies — Read more / Contribute
by reebee3
on Oct 08, 2015 at 13:52

    Hello! I am trying to write a script that detects SNPs and their position in DNA sequences. Simply put, A SNP is when there is a change in A, T, C, or G between sequences, therefore...

    A could change to T, C, to G

    T could change to C, G, or A

    G could change to C, T or A

    C could change to G, T or A

    For Example:

    Sequence 1: ATGGAT

    Sequence 2: ACGGAG

    There are 2 SNPs here.

    SNP 1 is the T --> C is position 2 of the sequence. SNP 2 is the T -->G in position 6 of the sequence.

    Criteria for the script:

    Only 2 sequences can be entered on the command line The 2 sequences must be equal length Find the SNP and the position of the SNP (starting from position 1 not 0) Print out data- for example using the sample above

    Pos 2: T => C

    Pos 6: T =>G

    Found 2 SNPs.

    This is what I have so far, but I am not sure how to proceed...

    #!/usr/bin/env perl # file: use strict; use warnings; use autodie; my $number_seqs = scalar @ARGV; if($number_seqs != 2){ print "Please provide two sequences \n"; } for (my $i=0; $i<$number_seqs; $i++){ if(length($ARGV[$i]) != length($ARGV[0])){ print "Please ensure the sequences are the same length \n"; } } my $var = $ARGV[0]; print $var,"\n"; my $var2 = my $var[0]; print $var2,"\n";
When the only tool you have is a screwdriver...
4 direct replies — Read more / Contribute
by ExReg
on Oct 08, 2015 at 11:10

    I am trying to extend a tool that looks at files, searching for certain patterns. The tool is in perl and makes copious use of regular expressions. I came across a new pattern that has me scratching my head. I am trying to match a certain expression e that can have more than one definition ( shown in much simplified form ):

    1. e =~ u 2. e =~ uae 3. e =~ edefe 4. e =~ ebe 5. e =~ ec

    As you can see, all but the first are recursive matches. I could write the above as

    e =~ u|uae|edefe|ebe|ec

    Here is what I have so far: if I had only 1 and 2 from above, I could write the combination of 1 and 2 as

    e =~ u(?:au)*

    Likewise, for 1 and 3, I could write

    e =~ udufu

    For 1 and 4, I would have

    e =~ ubu

    and for 1 and 5, I would have

    e =~ uc

    To go further, I would have to combine more than two together, and I think it could get horrifyingly complex. Is there a way to tackle a problem like this with dynamic regexes, or is there a method for substituting the above together?

    I have perl 5.6, so I am slightly limited on what I can do. I do not know dynamic regexes well enough to frame the above with those. I cannot use CPAN or anything other than the screwdriver I have.

how to remove empty pipe delimiters in a line which doesn't contain any data
8 direct replies — Read more / Contribute
by rpinnam
on Oct 08, 2015 at 10:04
    I have a input pipe delimiter file as:

    IFB Northpole||| Alaska||| 907-555-5555

    Walmart||| Fairbanks||| Alaska

    Chicken||| Anchorage||| Alaska||| 907-555-5555

    Beef||| Somewhere|||||Over the Rainbow|||907-555-5555

    I want my output to be :

    IFB Northpole| Alaska| 907-555-5555|

    Walmart| Fairbanks| Alaska

    Chicken| Anchorage| Alaska| 907-555-5555

    Beef| Somewhere|Over the Rainbow|907-555-5555

    Here is my code :
    #!/usr/bin/perl @FILES = glob("*.txt"); foreach my $file (@FILES) { open my $fh, '<', $file; (my $fileName = $file) =~ s/\.[^.]+$//; open(my $output, '>', $fileName.".csv") or die "Could not open fil +e '$fileName' $!"; my @category; my @Detail; print $output ""; while (my $line = <$fh>) { chomp $line; @tokens = split /\|/, $line; chomp(@tokens); $objectName=$tokens[0]; if($objectName ne ""){ my @objectFields; $size = scalar(@tokens); @tokens = @tokens[1..$size]; foreach my $token (@tokens){ $token =~ s/\r|\n//g; push @objectFields,$token; } if($objectName eq "IFB Northpole"){ @Detail=@objectFields; }elsif($objectName eq "Walmart"){ @category=@objectFields; }elsif($objectName eq "Chicken"){ @category=@objectFields; }elsif($objectName eq "Beef"){ my @item = (@Detail,@category,@objectFields); print $output join("|", @item,@removeemptylines)."\n"; } } } close $output; close $fh; }
    How can i achieve this in perl? Any help would be appreciated.
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 imbibing at the Monastery: (5)
As of 2015-10-10 19:55 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (258 votes), past polls