473,573 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=$t ext\n";
ALL the variables in this print are uninitialized on every pass!

Am I missing something?

Jul 19 '05 #1
6 1569
dw

"Wesley Groleau" <we********@myr ealbox.com> wrote in message
news:yk******** ************@gb ronline.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=$t ext\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********@myr ealbox.com> wrote in message
news:yk******** ************@gb ronline.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=$t ext\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********@myr ealbox.com> wrote in message news:<yk******* *************@g bronline.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********@myr ealbox.com> wrote in
news:yk******** ************@gb ronline.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/AwUBPzDRj2PeouI eTNHoEQIXaACg+I +6/qDR6OMBCilT9csZ p+l/Vm4AoL9Z
V3b0cWj7poriArS 3k8sFrta2
=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
18884
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 any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it...
28
3261
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 a number of aspects to this simplification, but for me the unification of methods and functions is the biggest benefit. All methods look like...
176
8174
by: basecamp | last post by:
just checking the average age of programmers using this group -- thanks
121
9975
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 support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather...
6
1696
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. Some developers feel any function that returns an object should copy it. This gets pretty expensive performance wise and development wise and hard...
24
2162
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
1075
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 codings. The web layout is designed in with frame, using client script. Below are the tested result:
9
1467
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
2049
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 application on the client, that communicates with an application on the server via Webservices/Remoting/..) I would somehow think a smart client, but...
70
14973
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 might be the same as a font on another platform, but with different names. I'd like to be able to specify the font names that are "most equivalent." ...
0
7746
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7986
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8179
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7736
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8036
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6358
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5556
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3699
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.