Robert wrote:
I have currently wrote a simple script to attempt to create a list of
every letter combination this is a rough outline of what I want my
program to do . . .

A
B
C
...
AA
AB
AC

perl -le'print for "A" .. "ZZ"'


I used perl a bit for a high school project several years ago so I'm
not that good at it =(  Never the less I have extensively googled what
I am trying to accomplish and came across the join command.  I tried
to plug this into my code and get the desired output.

Here is what I have:


!/usr/bin/perl

use warnings;

use strict;

my @array = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M',
  'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', );

That can be written more simply as:

my @array = 'A' .. 'Z';

print join("\n", @array , );

You are missing a newline after the last @array element:

print join( "\n", @array ), "\n";

Or:

print join( "\n", @array, '' );

Or:

print map "$_\n", @array;


#
#
#So far so good I get the desired output for the first letter collum
#
#

!/usr/bin/perl

use warnings;

use strict;

my @array = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M',
  'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', );

my @first = join("\n", @array , );

print join(@first , @array );

The first argument of join() is evaluated in scalar context:

$ perl -le'print prototype "CORE::join"'
$@

And an array in scalar context returns the number of elements in the array. So your example

print join( @first, @array );

Is the same as:

print join( "1", @array );

Because @first has only one element.

#
#
#Here is where it gets messed up, the output that I get is as follows
# A1B1C1D1E1F1G1H1I1J1K1L1M1N1O1P1Q1R1S1T1U1V1W1X1Y1Z
#



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to