Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Print - format / presentation question

Reply
Thread Tools

Print - format / presentation question

 
 
Chris Vidal
Guest
Posts: n/a
 
      08-08-2003

This works fine

print "*" x 10;
print "\n";

But is there a way to print *'s then a newline in one line

print "*" x 10"\n"; doesnt work.

Tks




 
Reply With Quote
 
 
 
 
Graham Gough
Guest
Posts: n/a
 
      08-08-2003
>>>>> "Chris" == Chris Vidal <(E-Mail Removed)> writes:

Chris> print "*" x 10"\n"; doesnt work.

print "*" x 10, "\n";


 
Reply With Quote
 
 
 
 
Mothra
Guest
Posts: n/a
 
      08-08-2003
[snipped]
> print "*" x 10"\n"; doesnt work.
>

print "*" x10 . "\n";

Mothra


 
Reply With Quote
 
James Willmore
Guest
Posts: n/a
 
      08-08-2003
> This works fine
>
> print "*" x 10;
> print "\n";
>
> But is there a way to print *'s then a newline in one line
>
> print "*" x 10"\n"; doesnt work.


Try:

print "*" x 10, "\n";

HTH

Jim
 
Reply With Quote
 
Eric J. Roode
Guest
Posts: n/a
 
      08-08-2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Mothra" <(E-Mail Removed)> wrote in news:3f326806$(E-Mail Removed):

> [snipped]
>> print "*" x 10"\n"; doesnt work.
>>

> print "*" x10 . "\n";


Careful:

$ perl -le 'print "*"x10."\n"'
String found where operator expected at -e line 1, near "10."\n""
(Missing operator before "\n"?)
syntax error at -e line 1, near "10."\n""
Execution of -e aborted due to compilation errors.


- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPzQuYWPeouIeTNHoEQIDSQCgx6lt/s8F+KNxNQvFs6yQIATr/JMAoMig
62FX+XjzMl2FPD1fhmLGL1+Q
=H16C
-----END PGP SIGNATURE-----
 
Reply With Quote
 
Matt Garrish
Guest
Posts: n/a
 
      08-08-2003

"Eric J. Roode" <(E-Mail Removed)> wrote in message
news:Xns93D1C369A968Csdn.comcast@206.127.4.25...
>
> Careful:
>
> $ perl -le 'print "*"x10."\n"'
> String found where operator expected at -e line 1, near "10."\n""
> (Missing operator before "\n"?)
> syntax error at -e line 1, near "10."\n""
> Execution of -e aborted due to compilation errors.


Are you just trying to show that you can screw up the syntax, or are you
forgetting about associativity?

perl -le 'print("*"x10)."\n"'

I'll assume you were trying to make the former point, but your observation
doesn't make his response wrong, and he never claimed that it would work as
you wrote it. Whichever the case, though, you should have explained better
than to say "careful" and shown the error.

Matt


 
Reply With Quote
 
Eric J. Roode
Guest
Posts: n/a
 
      08-09-2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Matt Garrish" <(E-Mail Removed)> wrote in
news:eEWYa.7704$(E-Mail Removed):

>
> "Eric J. Roode" <(E-Mail Removed)> wrote in message
> news:Xns93D1C369A968Csdn.comcast@206.127.4.25...
>>
>> Careful:
>>
>> $ perl -le 'print "*"x10."\n"'
>> String found where operator expected at -e line 1, near "10."\n""
>> (Missing operator before "\n"?)
>> syntax error at -e line 1, near "10."\n""
>> Execution of -e aborted due to compilation errors.

>
> Are you just trying to show that you can screw up the syntax, or are
> you forgetting about associativity?
>
> perl -le 'print("*"x10)."\n"'


Are you just trying to show that you can misuse parentheses, or have you
forgotten the "if it looks like a function call, it is a function call"
rule?


> I'll assume you were trying to make the former point, but your
> observation doesn't make his response wrong, and he never claimed that
> it would work as you wrote it.


The way I wrote it was an exact copy, modulo whitespace, of what Mothra
posted. I happen to have respect for Mothra, based on his or her posts
here, which is why I didn't post a flame, and why I felt that nothing
more than "careful" plus an error dump was needed for Mothra to
understand that s/he should have known better than to post a quick
solution without making sure that it was correct.

However, I made the mistake of thinking that whitespace didn't matter to
Mothra's solution. It does. Not because of precedence, not because of
associativity, but because "10." is interpreted as a number, rather than
a number plus the concatenation operator. My mistake, not Mothra's; mea
culpa. But I didn't think that my mistake warranted a flame.

- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPzRB8WPeouIeTNHoEQKduQCg+THPa8sTZ0puBtlJ0J6WsH J8imsAoIuf
3KWqgyDx/pe2UpejwcivLX4l
=AGte
-----END PGP SIGNATURE-----
 
Reply With Quote
 
Matt Garrish
Guest
Posts: n/a
 
      08-09-2003

"Eric J. Roode" <(E-Mail Removed)> wrote in message
news:Xns93D1D19239CA8sdn.comcast@206.127.4.25...
> "Matt Garrish" <(E-Mail Removed)> wrote in
> news:eEWYa.7704$(E-Mail Removed):
> >
> > perl -le 'print("*"x10)."\n"'

>
> Are you just trying to show that you can misuse parentheses, or have you
> forgotten the "if it looks like a function call, it is a function call"
> rule?
>


The point was to show to you why the code you posted didn't work (i.e.,
10."\n" is misinterpreted if you leave out the whitespace). The parentheses
are there to return the . to the operator that it was in the original
example, and still make it work without whitespace (which I thought it was
your intention to show wouldn't)..

> The way I wrote it was an exact copy, modulo whitespace, of what Mothra
> posted.


Which means it was *not* an exact copy.

> I happen to have respect for Mothra, based on his or her posts
> here, which is why I didn't post a flame, and why I felt that nothing
> more than "careful" plus an error dump was needed for Mothra to
> understand that s/he should have known better than to post a quick
> solution without making sure that it was correct.


Regardless, don't you think it might have been helpful to the OP to explain
why you were posting?

> However, I made the mistake of thinking that whitespace didn't matter to
> Mothra's solution. It does. Not because of precedence, not because of
> associativity, but because "10." is interpreted as a number, rather than
> a number plus the concatenation operator.


Which breaks the proper associativity of the concatenation operator in the
example posted by Mothra. If you want to look at it as going from an
operator to not an operator that's fine with me, but it's not really here or
there.

> But I didn't think that my mistake warranted a flame.


Actually, there was no intent to flame, I just couldn't figure out why you
would post that error when it was of your own creation (I assumed you knew
why it wasn't working, but hadn't bothered to elaborate). Reread the first
line as a bewildered question rather than as the attack you seem to think it
is. As I've said, it made no sense why you were posting that error other
than to try and show how you could break his code, which isn't the most
challenging thing to do in Perl.

Matt


 
Reply With Quote
 
Matt Garrish
Guest
Posts: n/a
 
      08-09-2003

"Sam Holden" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed). ..
>
> Since it won't work with those parentheses that was a pretty silly way
> of going about it.
>


C:\>perl -le "print('*'x10).'\n'"
**********

C:\>

What doesn't work?

Matt


 
Reply With Quote
 
Matt Garrish
Guest
Posts: n/a
 
      08-09-2003

"Matt Garrish" <(E-Mail Removed)> wrote in message
news:X20Za.5624$(E-Mail Removed).. .
>
> What doesn't work?
>


My mistake. I should have tried without the -l option...

Matt


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
print a vs print '%s' % a vs print '%f' a David Cournapeau Python 0 12-30-2008 03:19 AM
Problem - I want to print Current Output of Pdf file and should print once.I get print dialog box but it is not working keto Java 0 05-30-2007 11:27 AM
print dos format file into unix format PengYu.UT@gmail.com Python 5 10-27-2006 01:56 PM
XML-based browser slideshow presentation format? rui.maciel@gmail.com XML 0 05-07-2006 08:46 PM
Unlarging the print to print using PDF file to print Bun Mui Computer Support 3 09-13-2004 03:15 AM



Advertisments