format @<<< 
Author Message
 format @<<<

Hello, I'm reading a long line of data from a text file and unpacking
it into an array of scalars. The last two scalars sometimes do not get
any data so they equal "" after I've unpacked them.

When I write the data to a file using the "format" and "write" commands
the last two fields don't print anything if they are "". What I want to
happen is for them to print spaces equal to the format that I set up.
How do I force this to happen?


$y, $z
.

If $y and $z = "" then:
It looks like this when it writes to the file: ""
I want it to look like this: "      "

Thanks!

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sat, 01 Mar 2003 07:41:56 GMT  
 format @<<<
Does anyone have any ideas on this? I'm still stuck on this piece of my
code. Everything else is working like a dream!

Thanks,
Rathmore

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 format @<<<
[posted & mailed]

Quote:

> format FILE =

> $y, $z
> .

> If $y and $z = "" then:
> It looks like this when it writes to the file: ""
> I want it to look like this: "      "

There is no special option to do this with format/write.  There are a
couple of techniques in perlform that you could use, though.

If you made the format:

  format FILE =

  $y, $z
  .

Then you could either open a pipe to yourself and just strip SOMETHING
with

    s/SOMETHING$//;

Or you could use the swrite in perlform to get the output in a scalar
and do the same thing.

But probably you'd just be better off just using printf:

    printf "%-4s%-4s" => $x, $y;

--
Rick Delaney



Tue, 04 Mar 2003 10:27:13 GMT  
 format @<<<

Quote:
> But probably you'd just be better off just using printf:

>     printf "%-4s%-4s" => $x, $y;

Anyway to left justify with printf? All my data is right justified now,
and that isn't what I want. It did print the spaces at the end that I
need though. :)

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 format @<<<

Quote:
> But probably you'd just be better off just using printf:

>     printf "%-4s%-4s" => $x, $y;

Anyway to left justify with printf? All my data is right justified now,
and that isn't what I want. It did print the spaces at the end that I
need though. :)

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 format @<<<
Ok, I'm an idiot. Please ignore. The '-' in there makes it left
justified. After reading your post, I looked up 'printf'
in "Programming Perl" and couldn't find much of anything. And no
reference at all to the '-' so I removed it. Then on a hunch, I put it
back, and bam! worked like magic.

Sorry, again.

**Also, deja.com hick-upped and posted my question twice. Can't wait to
get trn**

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 format @<<<


Quote:

> > But probably you'd just be better off just using printf:

> >     printf "%-4s%-4s" => $x, $y;

> Anyway to left justify with printf? All my data is right justified now,
> and that isn't what I want. It did print the spaces at the end that I
> need though. :)

That is called left-alignment, as specified by the '-' in the format
specifier.  You can specify minimum and maximum field width and whether
the text is padded with spaces on the right (left-aligned) or on the
left (right-aligned).

perldoc -f sprintf

--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. ^<<<<<<<<<<<~~ with \n

2. ^<<<<<<<<<<< ~~ format question

3. Using $: and ^<<<<~~~ in formatting

4. How can I make @<<<<<<<<< variable ?

5. How can grep the 8th of Field <<<<<<<<

6. Question on Cutting and Paste things in a File <<<<<<<<

7. <<<<<< HELP >>>>>>>>

8. 4.036 Bug using $: and ^<<<~~ fields

9. >>>> A Singaporean Girl looking for more penpals!!<<<<<

10. >>>Please add your Perl Script to the Perlcoders Archive of free scripts <<<<

11. Regexp: match '<:a<:c:>b:>', not '<:a<:c:>'

12. FAQ 4.36: Why don't my E<lt>E<lt>HERE documents work?

 

 
Powered by phpBB® Forum Software