CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
How to write information from one variable to another?

 



digioleg54
User

Apr 20, 2017, 11:03 AM

Post #1 of 7 (1154 views)
How to write information from one variable to another? Can't Post

If I have UNIX:


Code
`echo $short_desc > $f_pin`;


Can I write instead

Code
print $short_desc > $f_pin


Or I have to open $f_pin
then concatenate $short_desc?


FishMonger
Veteran / Moderator

Apr 20, 2017, 11:12 AM

Post #2 of 7 (1153 views)
Re: [digioleg54] How to write information from one variable to another? [In reply to] Can't Post

You need to open a filehandle and print to that handle.


digioleg54
User

Apr 20, 2017, 12:13 PM

Post #3 of 7 (1150 views)
Re: [FishMonger] How to write information from one variable to another? [In reply to] Can't Post

Will it overwrite what is already in that file?


FishMonger
Veteran / Moderator

Apr 20, 2017, 12:19 PM

Post #4 of 7 (1147 views)
Re: [digioleg54] How to write information from one variable to another? [In reply to] Can't Post

It depends on the mode you choose when opening the filehandle. You can open it in write mode or append mode.

http://perldoc.perl.org/functions/open.html

Which mode do you want?


(This post was edited by FishMonger on Apr 20, 2017, 12:20 PM)


digioleg54
User

Apr 20, 2017, 12:36 PM

Post #5 of 7 (1141 views)
Re: [FishMonger] How to write information from one variable to another? [In reply to] Can't Post

Append. ">>"


FishMonger
Veteran / Moderator

Apr 20, 2017, 12:39 PM

Post #6 of 7 (1141 views)
Re: [digioleg54] How to write information from one variable to another? [In reply to] Can't Post

Wait, it looks like I misread your question. I thought you were working with files, not variables.

You just need to make a simple assignment if you want to copy the var.

Code
$f_pin = $short_desc;


or, if you want to append

Code
$f_pin .= $short_desc;



(This post was edited by FishMonger on Apr 20, 2017, 12:40 PM)


digioleg54
User

Apr 20, 2017, 12:41 PM

Post #7 of 7 (1138 views)
Re: [FishMonger] How to write information from one variable to another? [In reply to] Can't Post

Please read my next question. Seems like I mislead you

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives