Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Assigning a string with a ' in it

Posted on 2011-03-25
14
Medium Priority
?
227 Views
Last Modified: 2012-05-11
How can I assign the following data to $string?  It has a ' in the line so I'm having trouble with it.


Target Name: s02asqlp_MSSQL_DB Target Type: Microsoft SQL Server Host Name: s02asqlp.na.ipaper.com Metric Name: type Key Name: Type of Record;Record Number Key Value: Application;3653034 TimeStamp: Mar 25, 2011 10:10:28 AM CDT Severity: Warning Message: Event generated for source (SQLSERVERAGENT) at time Fri, Mar 25, 2011, 10:08:00 AM. Details - User[]:Category[Job Engine]:Description[SQL Server Scheduled Job 'Log Shipping Alert Job - Restore' (0x5147AB34F8A62A4F8CF18821274B107E) - Status: Failed - Invoked on: 2011-03-25 10:08:00 - Message: The job failed. The Job was invoked by Schedule 494 (Log Shipping Alert Job - Restore). The last step to run was step 1 (Log Shipping Alert Job - Restore). ] Rule Name: DSQLDBSL_PROD_102608472 Rule Owner: DSYSMAN Metric Value: Warning : 9F351B69978130ADE0440021283CA56A : 0 : 0 : 1 : 9F351B69978130ADE0440021283CA56A
0
Comment
Question by:David Aldridge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
14 Comments
 
LVL 27

Expert Comment

by:wilcoxon
ID: 35216187
$string = <<"END_STRING";
Target Name: s02asqlp_MSSQL_DB Target Type: Microsoft SQL Server Host Name: s02asqlp.na.ipaper.com Metric Name: type Key Name: Type of Record;Record Number Key Value: Application;3653034 TimeStamp: Mar 25, 2011 10:10:28 AM CDT Severity: Warning Message: Event generated for source (SQLSERVERAGENT) at time Fri, Mar 25, 2011, 10:08:00 AM. Details - User[]:Category[Job Engine]:Description[SQL Server Scheduled Job 'Log Shipping Alert Job - Restore' (0x5147AB34F8A62A4F8CF18821274B107E) - Status: Failed - Invoked on: 2011-03-25 10:08:00 - Message: The job failed. The Job was invoked by Schedule 494 (Log Shipping Alert Job - Restore). The last step to run was step 1 (Log Shipping Alert Job - Restore). ] Rule Name: DSQLDBSL_PROD_102608472 Rule Owner: DSYSMAN Metric Value: Warning : 9F351B69978130ADE0440021283CA56A : 0 : 0 : 1 : 9F351B69978130ADE0440021283CA56A
END_STRING
0
 
LVL 27

Accepted Solution

by:
wilcoxon earned 1600 total points
ID: 35216200
Or if you want to make sure nothing in the data gets interpolated, you can use

$string = <<'END_STRING';

as the opening line.
0
 
LVL 4

Assisted Solution

by:dagesi
dagesi earned 400 total points
ID: 35216259
Considering the size, wilcoxon's option is probably best.

For smaller amounts, use q, where everything contained within the parens becomes part of the string.

$bar = q(everything here is included, including the 'quotes');
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:David Aldridge
ID: 35216468
Ok, the $string<<'END_STRING'; option seems to be working, but what if I want to get the data from @ARGV?  Sorry.. I should have added that to the original question.  That data is passed to the script.
0
 
LVL 27

Expert Comment

by:wilcoxon
ID: 35216611
I don't follow.  Is the data in $ARGV[0] or is it one line per @ARGV element or something else?

If the data is already in @ARGV, you can just assign it to string:

$string = shift; # or $string = $ARGV[0];
#or
$string = join "\n", @ARGV;

If you are saying the issue is a shell issue then the easiest thing to do is to put the data in a file and call your script as:

script.pl < file_containing_data

and the script could have:

$string = join '', <>;
0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35216873
Currently, I'm getting the data in like this:

my $string = join(' ', @ARGV) or die;

It gets assigned, but it has the extra ' in it so when I try to use it to remove unwanted data like:

if ( $string =~ /Warning \: .* \: 0 \: 0 \: 1 \: .*/ ) {      
      $string =~ s/Warning \: .* \: 0 \: 0 \: 1 \: .*//;
}

It breaks because of the extra '.
0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35216900
Sorry, I guess I could have been a bit more clear in the beginning.
0
 
LVL 27

Expert Comment

by:wilcoxon
ID: 35217178
What makes you think it is breaking because of the extra ' in the data?

What are you trying to do with your code?  It is doing exactly what you are telling it (which may not be what you actually want).
0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35217868
The "Warning" section which is at the end, isn't included in the substitution because of the extra ' in the string.
0
 
LVL 27

Expert Comment

by:wilcoxon
ID: 35217918
How so?  The final warning message is removed?

See blocks below...
### text after running your code
Target Name: s02asqlp_MSSQL_DB Target Type: Microsoft SQL Server Host Name: s02asqlp.na.ipaper.com Metric Name: type Key Name: Type of Record;Record Number Key Value: Application;3653034 TimeStamp: Mar 25, 2011 10:10:28 AM CDT Severity: Warning Message: Event generated for source (SQLSERVERAGENT) at time Fri, Mar 25, 2011, 10:08:00 AM. Details - User[]:Category[Job Engine]:Description[SQL Server Scheduled Job 'Log Shipping Alert Job - Restore' (0x5147AB34F8A62A4F8CF18821274B107E) - Status: Failed - Invoked on: 2011-03-25 10:08:00 - Message: The job failed. The Job was invoked by Schedule 494 (Log Shipping Alert Job - Restore). The last step to run was step 1 (Log Shipping Alert Job - Restore). ] Rule Name: DSQLDBSL_PROD_102608472 Rule Owner: DSYSMAN Metric Value:

Open in new window

### original text
Target Name: s02asqlp_MSSQL_DB Target Type: Microsoft SQL Server Host Name: s02asqlp.na.ipaper.com Metric Name: type Key Name: Type of Record;Record Number Key Value: Application;3653034 TimeStamp: Mar 25, 2011 10:10:28 AM CDT Severity: Warning Message: Event generated for source (SQLSERVERAGENT) at time Fri, Mar 25, 2011, 10:08:00 AM. Details - User[]:Category[Job Engine]:Description[SQL Server Scheduled Job 'Log Shipping Alert Job - Restore' (0x5147AB34F8A62A4F8CF18821274B107E) - Status: Failed - Invoked on: 2011-03-25 10:08:00 - Message: The job failed. The Job was invoked by Schedule 494 (Log Shipping Alert Job - Restore). The last step to run was step 1 (Log Shipping Alert Job - Restore). ] Rule Name: DSQLDBSL_PROD_102608472 Rule Owner: DSYSMAN Metric Value: Warning : 9F351B69978130ADE0440021283CA56A : 0 : 0 : 1 : 9F351B69978130ADE0440021283CA56A

Open in new window

0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35217977
I get "Bareword found where operator expected, near "Log"
Syntax error, near "Log Shipping "
Bad name after Restore'.
0
 
LVL 27

Expert Comment

by:wilcoxon
ID: 35218013
That error is not coming from the code you posted (at least I'm not getting it).  Can you post your whole script?  And exactly how is the script being called?
0
 
LVL 1

Author Comment

by:David Aldridge
ID: 35218432
I should have known someone changed something.  The application sending the trap was modified.  Thank you for your help and the code you originally gave me will come to great use!

Sorry for taking so much of your time when I should have done a little more snooping around.
0
 
LVL 4

Expert Comment

by:dagesi
ID: 35218579
thx for the assist...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question