473,396 Members | 1,975 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,396 software developers and data experts.

What did I screw up?


Actually, 95% of this is copied from something else
that supposedly works. (And from what I know of perl,
I thought it would work, too.)

But in a loop,

print $_ . "\n"; # first line is "0 HEAD"
# second is "1 SOUR hand-edited blah blah ...."

# Parse record
/^(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/;
$level = $1; # Save the level number
$label = $2; # Save the label (if specified)
$tag = uc($3); # Uppercase the tag
$text = $4; # Save everything else

print " " x $level . "$label=$tag=$text\n";
ALL the variables in this print are uninitialized on every pass!

Am I missing something?

Jul 19 '05 #1
6 1563
dw

"Wesley Groleau" <we********@myrealbox.com> wrote in message
news:yk********************@gbronline.com...

print $_ . "\n"; # first line is "0 HEAD"
# second is "1 SOUR hand-edited blah blah ....."
# Parse record
/^(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/;
$level = $1; # Save the level number
$label = $2; # Save the label (if specified)
$tag = uc($3); # Uppercase the tag
$text = $4; # Save everything else

print " " x $level . "$label=$tag=$text\n";
ALL the variables in this print are uninitialized on every pass!


what are the @'s in there for?

/^(\d+)\s+(\S+)?\s*(\S+)\s+(.*)/

However, this still doesn't quite look like what you want... since your
first line had just the level and label....

/^(\d+)\s+(\S+)\s+(?:(\S+)\s+(.*))?/
Jul 19 '05 #2
dw wrote:
"Wesley Groleau" <we********@myrealbox.com> wrote in message
news:yk********************@gbronline.com...
print $_ . "\n"; # first line is "0 HEAD"
# second is "1 SOUR hand-edited blah blah
...."
# Parse record
/^(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/;
$level = $1; # Save the level number
$label = $2; # Save the label (if specified)
$tag = uc($3); # Uppercase the tag
$text = $4; # Save everything else

print " " x $level . "$label=$tag=$text\n";
ALL the variables in this print are uninitialized on every pass!

what are the @'s in there for?


The protocol (GEDCOM) has some records with a label or
ID always delimited by at-signs.
/^(\d+)\s+(\S+)?\s*(\S+)\s+(.*)/

However, this still doesn't quite look like what you want... since your
first line had just the level and label....

/^(\d+)\s+(\S+)\s+(?:(\S+)\s+(.*))?/


Level is the number, first field. Label is not in either
of the first two lines, but it is in the following line:

0 @WWG-1954@ INDI

But the problem was that later lines got error messages
about using uninitialized variables. And those variables
happened to be $level, $label, and $tag. (I haven't tried
to use $text yet.)

If there is something wrong with a /regexp/ does it
just do nothing at all? It generated no error message
or warning (I used -w on invocation) at that point.
And the debugger stepped over it without comment.

Jul 19 '05 #3
Wesley Groleau <we********@myrealbox.com> wrote in message news:<yk********************@gbronline.com>...

The script seem OK, except for:
/^(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/;


are the "@" characters really suposed to be in file. If not try without them, so:

/^(\d+)\s+(\S+)?\s*(\S+)\s+(.*)/;

Emil
Jul 19 '05 #4
Emil wrote:
The script seem OK, except for:
/^(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/;


are the "@" characters really suposed to be in file. If not try without them, so:


OK, here's the format:

Every line has a level number and a tag, in that order.

1 MARR

Some lines have a label _between_ the level and the tag.

0 @WWG-1954@ INDI

ALL labels are bracketed by at-signs

Some lines have a cross-ref after the tag

1 FAMC @WWG-MTD-1987@

NO lines have both label and cross-ref

Some lines have text after the tag.

1 NAME W. Wesley /Groleau/

The problem is not in finetuning the regexp. The problem is that
the regexp is NOT DEFINING $1, $2, etc. even though it has sections
in parentheses.

The first non-space character on EVERY line is a digit.
So with

/^(\d+)\s+(......
$level = $1;
print $level;

why does perl complain that $level is uninitialized,
but NOT complain about the regexp?

I am beginning to wonder whether there is something wrong with
my installation of perl 5.6

Jul 19 '05 #5
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Wesley Groleau <we********@myrealbox.com> wrote in
news:yk********************@gbronline.com:
# Parse record
/^(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/;


Hi Wesley,

I just wanted to chime in here and point out two things that nobody else
has mentioned yet:

First, you should *always* test the success or failure of a regex match!
As follows:

if (/^(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/)
{
....it succeeded....
}
else
{
....it failed to match....
}

Second, comp.lang.perl is a defunct newsgroup. You'll get a better
response if you post to comp.lang.perl.misc, which is where general Perl
questions should be posted.

Good luck,
- --
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/AwUBPzDRj2PeouIeTNHoEQIXaACg+I+6/qDR6OMBCilT9csZp+l/Vm4AoL9Z
V3b0cWj7poriArS3k8sFrta2
=NGTh
-----END PGP SIGNATURE-----
Jul 19 '05 #6
First, you should *always* test the success or failure of a regex match!
Good advice. Wish I'd thought of it. I know now. :-)
Second, comp.lang.perl is a defunct newsgroup. You'll get a better
response if you post to comp.lang.perl.misc, which is where general Perl


Ah, thanks.

Jul 19 '05 #7

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

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
28
by: David MacQuigg | last post by:
I'm concerned that with all the focus on obj$func binding, &closures, and other not-so-pretty details of Prothon, that we are missing what is really good - the simplification of classes. There are...
176
by: basecamp | last post by:
just checking the average age of programmers using this group -- thanks
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
6
by: mswlogo | last post by:
There are many threads on the lack of a true unmanaged C++ const like behavior in C# (.Net) and that's not what this topic is about. The topic is, what is the best practical way to live with it. ...
24
by: Dave | last post by:
Maybe I'm missing something here, but I can't see the purpose of the 'finally' keyword. What is the difference between: try { doSomething() } catch { handleError(); }
0
by: Kelmen Wong | last post by:
Greeting, We have an ASP.NET app, developed using c#. There's a feature which a page (UserControl) when postback, it will download a PDF/Excel file through typical Response and Content Header...
9
by: dotnettester | last post by:
Hi, Can any one point me to a good resource on what to expect for .NET Applications when upgrading from IIS 5.0 to IIS 6.0 We are thinking to move to IIS 6.0 but fear...... Thanks,
10
by: Pieter Coucke | last post by:
Hi, What's in general the most performant for a VB.NET Windows Forms (2.0) application: - a fat client (everything one the client, the server hosts only the database) - a smart client (an...
70
by: axlq | last post by:
I'm trying to design my style sheets such that my pages have similar-looking fonts different platforms (Linux, Mac, Adobe, X-Windows, MS Windows, etc). The problem is, a font on one platform...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.