Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: printing every 2nd entry in a list backwards

by Discipulus (Prior)
on May 19, 2017 at 12:31 UTC ( #1190604=note: print w/replies, xml ) Need Help??


in reply to printing every 2nd entry in a list backwards

Welcome apprentice.. consider signing in

If i have understood the question you can:

UPDATE: ok i have misunderstood.. what i'm doing there is: given a file and a sequence of numbers, for this file print the reverse line order skipping even entries.

use strict; use warnings; # shift the file from args my $file_path = shift @ARGV; # a simple switch my $sw = 1; # take indices in reverse order and skipping 2th 4th.. my @wanted_lines = grep {$sw++ and $sw % 2 == 0} reverse @ARGV; open my $fh, '<', $file_path or die "unable to open $file_path! $!"; # in list context eat all the file at once my @all_lines = <$fh>; # of those all lines print a slice: the slice is @wanted_lines # with all valuse lowered by one because indices of array start at 0 # lines starts a 1 print for @all_lines[map{$_-1}@wanted_lines]; # invoke like: # inverted_alternated.pl file_to_read.txt 1 2 3 4

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1190604]
help
Chatterbox?
[marto]: better: "If a type of behaviour, event, or situation is par for the course, it is not good but it is normal or as you would expect"
[Discipulus]: thanks i was unable to decide where to split the sentece
[marto]: FWIW search.cpan rarely has issues, see http://noc.perl. org for a route to report problems
[oakbox]: thanks, marto.
[marto]: there was a period where search.cpan had some frequent outages for (IIRC) a couple of weeks. I've not had any problems since, until today.
[marto]: this was about 16 months ago maybe. the noc team are, in my experience, very responsive to reports of issues, so please raise the issue after checking known problems/outages

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2017-07-26 10:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (389 votes). Check out past polls.