473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

expression eats newline

The following Perl script

print ((time/86400) % 4), " foo foo foo foo\n";
print "bar\n";

produces the output

0bar

What happened to " foo foo foo foo\n"?

print 12, " foo\n";

prints '12 foo' and a newline. Ergo, ((time/86400) % 4) should just
be another numeric expression, just like 12, shouldn't it? Or am I
missing something really stupid?

Thanks in advance.
- Jerry Oberle
perl -e 'printf "mailto%c%s%c%s%cchase%ccom%c", 58, "Gerard", 46,
"Oberle", 64, 46, 10;'
Jul 19 '05 #1
3 2716
Gerard Oberle wrote:

(snipped)
The following Perl script print ((time/86400) % 4), " foo foo foo foo\n";
print "bar\n"; produces the output 0bar What happened to " foo foo foo foo\n"?

You are neglecting Perl command formats, which are
typically, command() as with print().

Your parentheses are the problem. Perl is doing
precisely what your syntax indicates to do.

Compare these to your syntax:

print time/86400 % 4, " foo foo foo foo\n";
print "bar\n";

print (((time/86400) % 4), " foo foo foo foo\n");
print "bar\n";
Purl Gurl
--

#!perl -w

print ((time/86400) % 4), " foo foo foo foo\n";
print "bar\n";
PRINTED RESULTS:
________________

print (...) interpreted as function at test.pl line 3.
Useless use of a constant in void context at test.pl line 3.
0bar
Jul 19 '05 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

go*****@hotmail.com (Gerard Oberle) wrote in
news:c4**************************@posting.google.c om:
The following Perl script

print ((time/86400) % 4), " foo foo foo foo\n";


Perl has a rule when it comes to interpreting statements like this:

"if it looks like a function, it IS a function."

So, because of your parentheses, it is as if you wrote:

$x = print( (time/86400)%4 );
$x, " foo foo foo foo\n";

The solution is either to add a + before the first parenthesis:

print +((time/86400) % 4), " foo foo foo foo\n";

or to add another set of parentheses:

print (((time/86400) % 4), " foo foo foo foo\n");
For your future reference, comp.lang.perl is a defunct newsgroup. General
perl questions should be posted to comp.lang.perl.misc; you'll get a better
response there.
- --
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/AwUBPynqOmPeouIeTNHoEQIu7ACghrgjRzXwWjijpWA+ihwOUK SSZQEAnRAr
dlcsK2oa9GH1M3p1WYE8AUVW
=2btu
-----END PGP SIGNATURE-----
Jul 19 '05 #3
Gerard Oberle wrote:

(Topic is use of parentheses with Perl print)

(snipped)
As I suspected, I was missing something stupid.
Not really stupid. It is very rare to read Perl code
which employs C style parentheses with a print command.
Almost all books and reference sources omit parentheses
within examples of print commands. Most do not know of
this until a rather quirky problem pops up.

As for comp.lang.perl being defunct, I am not sure how one can
determine that. groups.google.com still carries it, and there are
lots of recent postings, so I assume people are still using it.


Many if not most news servers carry this group and alt.perl as well.
Humors me when reading those proclaiming this group does not exist.
Quite the oxymoron, this is, posting to a group which does not exist.
Purl Gurl
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David Bear | last post by:
I'm trying to understand how regex's are interpreted out of strings objects. for example, If I have a string that has newline chars in it, how can I get a re.split to respect where the newlines...
7
by: steve bull | last post by:
I have the following code snippet to read the colorRange attributes for the colorRangeSwatch in the xml file listed below. string expr = "/swatches/colorRangeSwatch/colorRange";...
5
by: stanlo | last post by:
hello, i thought it was wise to include my program. my main problem is i wantto adapt the program to do only multiplication ,division,addition, and subtraction and what ever i do there is an...
3
by: Guoqi Zheng | last post by:
Dear sir, On regular expression, a . means Match anything except newline. How about if I need it to includes newline as well? I try , but it seems not working. and idea? -- Kind regards
3
by: Craig | last post by:
Hi I'm having some troubles getting my regex to work. I have a string as follows The "quick and brown" fox "jumped over the" lazy dog. The output should be as follows: The "quick and brown"...
12
by: stevebread | last post by:
Hi, I am having some difficulty trying to create a regular expression. Consider: <tag1 name="john"/ <br/<tag2 value="adj__tall__"/> <tag1 name="joe"/> <tag1 name="jack"/> <tag2...
3
by: shapper | last post by:
Hello, I have a regular expression to validate email addresses: "\w+(\w+)*@\w+(\w+)*\.\w+(\w+)*" Now I need to force all emails to be from a given domain, for example, accept only:...
28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
12
by: chaarmann | last post by:
I want to format a long line of text by inserting newline-characters in a way that the printout contains small rows with maximum 80 chars. But I am not allowed to split inside the sequence "<(>"....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.