• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

Assigning a string with a ' in it

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
David Aldridge
Asked:
David Aldridge
  • 6
  • 6
  • 2
2 Solutions
 
wilcoxonCommented:
$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
 
wilcoxonCommented:
Or if you want to make sure nothing in the data gets interpolated, you can use

$string = <<'END_STRING';

as the opening line.
0
 
dagesiCommented:
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
David AldridgeAuthor Commented:
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
 
wilcoxonCommented:
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
 
David AldridgeAuthor Commented:
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
 
David AldridgeAuthor Commented:
Sorry, I guess I could have been a bit more clear in the beginning.
0
 
wilcoxonCommented:
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
 
David AldridgeAuthor Commented:
The "Warning" section which is at the end, isn't included in the substitution because of the extra ' in the string.
0
 
wilcoxonCommented:
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
 
David AldridgeAuthor Commented:
I get "Bareword found where operator expected, near "Log"
Syntax error, near "Log Shipping "
Bad name after Restore'.
0
 
wilcoxonCommented:
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
 
David AldridgeAuthor Commented:
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
 
dagesiCommented:
thx for the assist...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now