![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Append string to columns from 2 files | karthikn7974 | Shell Programming and Scripting | 3 | 04-28-2008 09:32 AM |
| awk printing all columns after (but including) $n | cassj | UNIX for Dummies Questions & Answers | 2 | 03-05-2008 03:22 PM |
| Need help in AWK;Search String and rearrange columns | spring_buck | Shell Programming and Scripting | 2 | 04-05-2007 11:40 AM |
| Printing Columns in Unix | Terrible | Shell Programming and Scripting | 3 | 11-27-2006 06:43 AM |
| printing columns | cdunavent | Shell Programming and Scripting | 3 | 06-07-2003 11:31 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Perl, printing a string into columns
How can I use Perl to a take a string of 10 characters and print the last five characters of the string in columns 1-5 and the first five in columns 6-10?
Result: 0123456789 5 0 6 1 7 2 8 3 9 4 |
|
||||
|
If the string is a constant and the output is also constant, use 'substr' to put each character into variables then print out in any format you want.
Code:
my $first_char = substr $_, 0, 1; my $second_char = substr $_, 1, 1; my $third_char = substr $_, 2, 1; my $fourth_char = substr $_, 3, 1; . . . print "$sixth_char\t$first_char\n"; print "$seventh_char\t$second_char\n"; . . . and so on |
|
||||
|
So I dug around and found some code similar to what I want, but not quite (similar in that it can break a string down by characters).
#!/usr/bin/perl print "Enter 10 characters\n"; chomp ($foo=<STDIN>); { %seen = (); foreach $char (split //, $foo) { $seen{$char}++; } print "broken into columns: ", sort(keys %seen), "\n"; } print $foo; How can I get this to print characters into columns then? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|