For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2004 > question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author question
DBSMITH@OhioHealth.com

2004-08-04, 8:55 pm

Is the last unless statement saying "break out of the loop only when @a is
read completely through?
I also have a formatting question. The output is printing a ' after a
newline and I have played with the code by moving "print $tick in and
outside the loop, but cannot get it to work. Here is what I mean:

-w 'barcode=E01497 or barcode=E01496 or barcode=E01332 or
barcode=E00405
'edm01:/usr/local/bin/perld>>

I would like to have the tick right after the last element E string

#!/usr/local/bin/perl -w
use strict;
open (FH,"/usr/local/bin/perld/derektapes") or die "cannot open FH: $!
\n";
my $w_param="-w ";
my $tick="'";
my $b_param="barcode=";
my $or_string=" or ";
chomp ( my @a = <FH> );

# $a[$i]=$_;
# $i++;
# print map {$_, "\n"} @a;

print $w_param, $tick;
while (@a) {
my @output = ();
for ( 1..4 ) {
push @output, $b_param . shift @a;
last unless @a;
}
print join ($or_string, @output),"\n";
}
print $tick;


thank you,
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams


Gunnar Hjalmarsson

2004-08-04, 8:55 pm

DBSMITH@OhioHealth.com wrote:
> Is the last unless statement saying "break out of the loop only
> when @a is read completely through?


In effect: Yes.

> I also have a formatting question. The output is printing a '
> after a newline


A wild guess would be that it's because the "'" is printed after the
printing of a "\n". ;-) Have you tried:

print join ($or_string, @output), $tick, "\n";

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
John W. Krahn

2004-08-04, 8:55 pm

DBSMITH@OhioHealth.com wrote:

> Subject: question


Please try to use a more descriptive subject line. :-)


> Is the last unless statement saying "break out of the loop only when @a is
> read completely through?
> I also have a formatting question. The output is printing a ' after a
> newline and I have played with the code by moving "print $tick in and
> outside the loop, but cannot get it to work. Here is what I mean:
>
> -w 'barcode=E01497 or barcode=E01496 or barcode=E01332 or
> barcode=E00405
> 'edm01:/usr/local/bin/perld>>
>
> I would like to have the tick right after the last element E string
>
> #!/usr/local/bin/perl -w
> use strict;
> open (FH,"/usr/local/bin/perld/derektapes") or die "cannot open FH: $!
> \n";
> my $w_param="-w ";
> my $tick="'";
> my $b_param="barcode=";
> my $or_string=" or ";
> chomp ( my @a = <FH> );
>
> # $a[$i]=$_;
> # $i++;
> # print map {$_, "\n"} @a;
>
> print $w_param, $tick;
> while (@a) {
> my @output = ();
> for ( 1..4 ) {
> push @output, $b_param . shift @a;
> last unless @a;
> }
> print join ($or_string, @output),"\n";
> }
> print $tick;


You are printing $tick after the newline. Try printing it before the newline.

print join ($or_string, @output),"$tick\n";



John
--
use Perl;
program
fulfillment
DBSMITH@OhioHealth.com

2004-08-09, 3:56 pm

well yes I thought I tried that, but maybe I type something wrong b/c I am
not seeing what I remember. Yours works!

thanks!

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145





Gunnar Hjalmarsson <noreply@gunnar.cc>
08/04/2004 06:12 PM


To: beginners@perl.org
cc:
Subject: Re: question


DBSMITH@OhioHealth.com wrote:
> Is the last unless statement saying "break out of the loop only
> when @a is read completely through?


In effect: Yes.

> I also have a formatting question. The output is printing a '
> after a newline


A wild guess would be that it's because the "'" is printed after the
printing of a "\n". ;-) Have you tried:

print join ($or_string, @output), $tick, "\n";

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>





Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com