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

$/ Problem

'Lo Everyone,
I'm creating a script that parses XML files (already been done, I know, but I want to try it myself), and I've run into a bit of trouble. I am using the variable $/ , but I can only set it to a value that's one character long.
Expand|Select|Wrap|Line Numbers
  1. $/ = "a"; //works
  2. $/ = "\n"; //works
  3. $/ = "4"; //works
  4. $/ = "kitten"; //DOESN'T WORK!!!!?!?!?!?!?!?!?!?
  5. $/ = "\n\n"; //DOESN'T WORK !!!!?!?!?!?!?!?!?!?
  6.  
Does anybody know why I'm unable to assign a value to $/ if it's more than one character long? I learned perl from http://www.perl.org/books/beginning-perl/ and that said that you could set it to a multi-character string just fine.... any ideas?
I'm running perl 5.8.6, if that matters...?

Thanks All,
Andrew

PS: I tried using single quotes, double quotes, variables, plenty of options, but I couldn't make it work. Maybe I'm missing something... I hope so!
Jan 19 '08 #1
8 1144
KevinADC
4,059 Expert 2GB
It should be no problem, you can assign $/ a multi-character string as it's value. Must be something else wrong in your code, which we can't see.
Jan 19 '08 #2
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <studentlist>
  3. <class id="Geography">
  4. <student>
  5. <name>Lexi</name>
  6. <gender>F</gender>
  7. </student>
  8.  
  9. <student>
  10. <name>Nelle</name>
  11. <gender>F</gender>
  12. </student>
  13.  
  14. <student>
  15. <name>Josh</name>
  16. <gender>M</gender>
  17. </student>
  18.  
  19. <student>
  20. <name>Jason</name>
  21. <gender>M</gender>
  22. </student>
  23.  
  24. <student>
  25. <name>Ben</name>
  26. <gender>M</gender>
  27. </student>
  28.  
  29. <student>
  30. <name>Larry</name>
  31. <gender>M</gender>
  32. </student>
  33. </class>
  34.  
  35. <class id="English">
  36. <student>
  37. <name>Caleb</name>
  38. <gender>M</gender>
  39. </student>
  40.  
  41. <student>
  42. <name>Emily</name>
  43. <gender>F</gender>
  44. </student>
  45.  
  46. <student>
  47. <name>Adelle</name>
  48. <gender>F</gender>
  49. </student>
  50.  
  51. <student>
  52. <name>Mike</name>
  53. <gender>M</gender>
  54. </student>
  55.  
  56. </class>
  57. </studentlist>
  58.  
Expand|Select|Wrap|Line Numbers
  1. #!usr/bin/perl
  2. #Using hashes
  3. use warnings;
  4. use strict;
  5.  
  6. open(XMLFILE, "students.xml");
  7.  
  8. $/ = "</student>";
  9.  
  10. for (<XMLFILE>){
  11. print $_;
  12. print "ALALALALALALALA\n";
  13. }
  14. close(XMLFILE);
  15.  
That's everything. People on other forums were unable to find any bugs... one person even said that it worked perfectly fine on HIS computer! Any ideas why it wouldn't work on mine?
Jan 20 '08 #3
KevinADC
4,059 Expert 2GB
Was the XML file made on a windows computer and you are processing it on a Unix/Linux computer? Your code works for me on my Windows test server.
Jan 20 '08 #4
The file was made with a Mac (typed exactly as it appears into TextEdit) and it was run on a Mac (the BSD/Unix concoction, Darwin).
GAAAAAAAARGH! :)
It makes no sense!
Jan 20 '08 #5
KevinADC
4,059 Expert 2GB
What is the output you get when you run the code?
Jan 20 '08 #6
imac:~/begperl J$ perl abc.plx
??<?xml version="1.0" encoding="UTF-8"?>
<studentlist>
<class id="Geography">
<student>
<name>Lexi</name>
<gender>F</gender>
</student>

<student>
<name>Nelle</name>
<gender>F</gender>
</student>

<student>
<name>Josh</name>
<gender>M</gender>
</student>

<student>
<name>Jason</name>
<gender>M</gender>
</student>

<student>
<name>Ben</name>
<gender>M</gender>
</student>

<student>
<name>Larry</name>
<gender>M</gender>
</student>
</class>

<class id="English">
<student>
<name>Caleb</name>
<gender>M</gender>
</student>

<student>
<name>Emily</name>
<gender>F</gender>
</student>

<student>
<name>Adelle</name>
<gender>F</gender>
</student>

<student>
<name>Mike</name>
<gender>M</gender>
</student>

</class>
</studentlist>ALALALALALALALA
imac:~/begperl J$
There it is, run from the terminal.
Might the problem have to do with the "??" in font of the first line? An encoding problem, perhaps? It was saved as UTF-8, just like it says...
Jan 21 '08 #7
KevinADC
4,059 Expert 2GB
Sorry, but I don't know why you get that output. Maybe ask on perlmonks.com and see if anyone there has a clue.
Jan 21 '08 #8
Yeah..... this has happened to me once before. I was programming on a TI-83+ Calculator, and it always got stuck on one line, even though everyone was sure that it was right. Thanks for your help. I'll try out the folks at perlmonks, but after that..... maybe I should update my version of perl, see if it goes away. Random works, sometimes......
Thanks again.
Jan 21 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
117
by: Peter Olcott | last post by:
www.halting-problem.com
18
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: =?Utf-8?B?am8uZWw=?= | last post by:
Hello All, I am developing an Input Methop (IM) for PocketPC / Windows Mobile (PPC/WM). On some devices the IM will not start. The IM appears in the IM-List but when it is selected from the...
1
by: sherifbk | last post by:
Problem description ============== - I have 4 clients and 1 server (SQL server) - 3 clients are Monitoring console 1 client is operation console - Monitoring console collects some data from...
9
by: AceKnocks | last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
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...
0
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,...
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
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...

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.