Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Print a big string formatted and in multiple lines

by haukex (Archbishop)
on Sep 30, 2016 at 17:51 UTC ( [id://1173019]=note: print w/replies, xml ) Need Help??


in reply to Print a big string formatted and in multiple lines

Hi alen129,

Please see How do I post a question effectively? - please use <code> tags to format not only your code but your data as well.

To convert the string '\n' (that is, a literal backslash followed by the letter n) to a newline (perhaps plus something else), you could do

$Detail =~ s/\\n/\n/g; # or $Detail =~ s/\\n/<br>\n/g; # for HTML

Hope this helps,
-- Hauke D

Replies are listed 'Best First'.
Re^2: Print a big string formatted and in multiple lines
by alen129 (Novice) on Sep 30, 2016 at 18:44 UTC
    Hauke D, The second line did it for me. Thank you so much. where can I learn more about this sort of string formatting?(what keyword do I search for?)

      Hi alen129,

      s/\\n/<br>\n/g is a search-and-replace regular expression, a good place to start is perlretut and perlrequick.

      Interpolation ('\n' vs. "\n" vs. "\\n") is discussed in a few different places, for example a bit in Scalar value constructors and Quote and Quote like Operators.

      Also, as mentioned as one of the points in the Basic debugging checklist, it's probably a good habit to get into to use a module like Data::Dumper or Data::Dump to look at the content your variables:

      my $Detail = 'Sep 30 2016 8:32AM CHP\nSep 30 2016 8:32AM SANTA ANA\n'; use Data::Dumper; $Data::Dumper::Useqq=1; print Dumper $Detail; # - or - use Data::Dump 'dump'; print dump $Detail;

      Both will unambiguously show you the content of the string in Perl's syntax, for example "Sep 30 2016 8:32AM CHP\\nSep 30 2016 8:32AM SANTA ANA\\n".

      Hope this helps,
      -- Hauke D

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1173019]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 19:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found